/**
* Assign the view handler
*/

viewHandler = Merchandise;

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

	var _instance = this;



	// 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 product items
		var productItems = dojo.query('#merchandiseProducts div.productItem div.photo');
		for (var x = 0; x < productItems.length; x++)
			{
			productItems[x].onmouseover = __eventHandlerProductItemOver;
			productItems[x].onmouseout = __eventHandlerProductItemOut;
			}
		productItems = dojo.query('#merchandiseProducts div.productItem h5');
		for (var x = 0; x < productItems.length; x++)
			{
			productItems[x].onmouseover = __eventHandlerProductItemOver;
			productItems[x].onmouseout = __eventHandlerProductItemOut;
			}
		}

	
	/**
	* Changes the page of photos displayed
	*
	* @param		pageUrl					The url of page of photos to load
	*/
	this.loadProductsPage = function(pageUrl)
		{
		// Update the content
		dojo.xhrGet(
			{
			url: pageUrl,
			preventCache: true,
			handleAs: "text",
				load: function(data)
					{
					// Add the new playlist in to the document
					document.getElementById('merchandiseProducts').innerHTML = data;

					// Add event handlers to product items
					var productItems = dojo.query('#merchandiseProducts div.productItem div.photo');
					for (var x = 0; x < productItems.length; x++)
						{
						productItems[x].onmouseover = __eventHandlerProductItemOver;
						productItems[x].onmouseout = __eventHandlerProductItemOut;
						}
					productItems = dojo.query('#merchandiseProducts div.productItem h5');
					for (var x = 0; x < productItems.length; x++)
						{
						productItems[x].onmouseover = __eventHandlerProductItemOver;
						productItems[x].onmouseout = __eventHandlerProductItemOut;
						}
					}
				}
			);
		}


	// Step 3. Define Private Methods
	
	/**
	* Event Handler: Mouse product item content
	*/
	function __eventHandlerProductItemOver()
		{
		this.parentNode.className = this.parentNode.className.replace(/\s?productItemOver/g, '') + ' productItemOver';
		}

	/**
	* Event Handler: Mouse product item content
	*/
	function __eventHandlerProductItemOut()
		{
		this.parentNode.className = this.parentNode.className.replace(/\s?productItemOver/g, '');
		}
	}
