/**
* Assign the view handler
*/

viewHandler = ShopOverview;

/**
* Creates a new object with methods used by the Shop Overview page
*
* @author				Matt Gifford
* @copyright			2007 Timeshifting Interactive Limited
*/
function ShopOverview()
	{
	// Step 1. Define Properties

	var _instance = this;

	this.detailPopupTimeout = null;
	this.detailDelayTimeout = null;
	this.detailCurrentSource = null;
	this.detailCurrentPopup = null;


	// Step 2. Define Public Methods

	/**
	* Sets up the initial page state and event handlers
	*/
	this.init = function()
		{
		// Call generic page init method
		this.base.init.call(this);

		// Add event handlers to category images
		var imgs = document.getElementById('shopContent').getElementsByTagName('img');
		for (var x = 0; x < imgs.length; x++)
			{
				// K
/*			imgs[x].onmouseover = __eventHandlerOverImage;
			imgs[x].onmouseout = __eventHandlerOutImage;
*/			}

		// Add event handlers to detail popups
		var divs = document.getElementById('shopContent').getElementsByTagName('div');
		for (var x = 0; x < divs.length; x++)
			{
			if (divs[x].className == 'detail')
				{
					// K
//				divs[x].onmouseover = __eventHandlerOverDetail;
//				divs[x].onmouseout = __eventHandlerOutDetail;
				}
			}
		}
	

	/**
	* Hides the category detail popups
	*/
	this.hideCategoryDetailPopups = function()
		{
		if (document.getElementById('shopInfoPopup'))
			{
			document.body.removeChild(document.getElementById('shopInfoPopup'));
			}
		}


	// Step 3. Define Private Methods


	/**
	* Event Handler: Shows detail popup on mouse over of image
	*/
	function __eventHandlerOverImage()
		{
		if (typeof(xhtml) == 'undefined')
			{
			return;
			}

		xhtml.detailCurrentSource = this;

		clearTimeout(xhtml.detailDelayTimeout);
		xhtml.detailDelayTimeout = setTimeout(
			function()
				{
				// Clear any pending timeouts and hide all the detail popups
				clearTimeout(xhtml.detailPopupTimeout);
				xhtml.hideCategoryDetailPopups();

				// Display the selected detail popup
				var categoryItem = xhtml.findParent(xhtml.detailCurrentSource, 'div');
				if (categoryItem)
					{
					xhtml.detailCurrentPopup = categoryItem.getElementsByTagName('div')[0].cloneNode(true);
					xhtml.detailCurrentPopup.id = 'shopInfoPopup';
					xhtml.detailCurrentPopup.className = 'shopInfoPopup';

					var position = xhtml.getObjectPosition(categoryItem.getElementsByTagName('div')[0]);
					xhtml.detailCurrentPopup.style.left = (position.x + 160) + 'px';
					xhtml.detailCurrentPopup.style.top = (position.y - 300) + 'px';

					document.body.appendChild(xhtml.detailCurrentPopup);
					}
				},
			750
			);
		}
	

	/**
	* Event Handler: Sets a hide of detail popup on mouse out of image
	*/
	function __eventHandlerOutImage()
		{
		if (typeof(xhtml) != 'undefined')
			{
			xhtml.detailPopupTimeout = setTimeout("xhtml.hideCategoryDetailPopups();", 1000);
			}
		}


	/**
	* Event Handler: Clears any pending timeouts on mouse over of div
	*/
	function __eventHandlerOverDetail()
		{
		clearTimeout(xhtml.detailPopupTimeout);
		}


	/**
	* Event Handler: Sets a hide of detail popup on mouse out
	*/
	function __eventHandlerOutDetail()
		{
		xhtml.detailPopupTimeout = setTimeout("xhtml.hideCategoryDetailPopups();", 500); // original value 1000
		}
	}

