/**
* Creates a new object for popup dialog management
*
* @author				Matt Gifford
* @copyright			2008 Timeshifting Interactive Limited
*/
dialogs = new Dialogs();
function Dialogs()
	{
	// Step 1. Define Properties

	var _instance = this;


	// Step 2. Define Public Methods

	/**
	* Displays the specified dialog
	*
	* @param		id			The dialog element's id
	*/
	this.show = function(id, form)
		{
		// Display the black overlay
		_showOverlay();

		// Display the dialog
		if (document.getElementById(id))
			{
			// Calcalute positioning
			var yPos = window.scrollY ? window.scrollY : (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
			yPos += 60;
			document.getElementById(id).style.top = yPos + 'px';

			// If a url was supplied
			if (arguments.length == 2)
				{
				document.getElementById(id).getElementsByTagName('input')[0].value = 'scheduleAddToBasket' + form;
				}

			// Display the dialog
			document.getElementById(id).className = document.getElementById(id).className.replace(/\s?\bhidden\b/g, '');
			}
		}


	/**
	* Hides the specified dialog
	*
	* @param		id			The dialog element's id
	*/
	this.hide = function(id)
		{
		// Hide the black overlay
		_hideOverlay();

		// Hide the dialog
		if (document.getElementById(id))
			{
			document.getElementById(id).className += ' hidden';
			}
		}



	// 3. Define Private Methods

	/**
	* Shows the black dialog background overlay
	*/
	function _showOverlay()
		{
		// Add the overlay if it doesn't already exist
		if (!document.getElementById('dialogBackgroundOverlay'))
			{
			var overlay = document.createElement('div');
			overlay.id = 'dialogBackgroundOverlay';
			overlay.style.position = 'absolute';
			overlay.style.left = '0px';
			overlay.style.top = '0px';
			overlay.style.background = '#000';
			overlay.style.zIndex = 500;
			overlay.style.opacity = 0.65;
			overlay.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=65)';
			document.getElementById('dialogContainer').insertBefore(overlay, document.getElementById('dialogContainer').firstChild);
			}

		// Resize the overlay
		var overlay = document.getElementById('dialogBackgroundOverlay');
		overlay.style.width = document.body.offsetWidth + 'px';
		overlay.style.height = document.body.offsetHeight + 'px';
		overlay.className = '';
		}


	/**
	* Hides the black dialog background overlay
	*/
	function _hideOverlay()
		{
		// Hide the overlay
		document.getElementById('dialogBackgroundOverlay').className = 'hidden';
		}
	}