/**
* Assign the view handler
*/

viewHandler = Product;

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

	var _instance = this;
	this.imageCache = [];



	// 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 tooltips to relate items
		var divs = YAHOO.util.Dom.getElementsByClassName('productsList', 'div', document.getElementById('productRelated'));
		if (0 < divs.length)
			{
			var anchors = divs[0].getElementsByTagName('a');
			for (var x = 0, title = '', tooltipHtml = ''; x < anchors.length; x++)
				{
				title = anchors[x].getAttribute('title');
				if (title != '')
					{
					tooltipHtml = '<div class="text"><span>' + title + '</span><img src="images/global-elements-tooltip-arrow.png"/></div>';
					anchors[x].setAttribute('title', '')
					var tooltip = new YAHOO.widget.Tooltip('categoryTooltip' + x, { context: anchors[x], text: tooltipHtml, preventoverlap: true, showDelay: 200, effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25} });
					}
				}
			}

		// Precache fullsize images
		var images = document.getElementById('productThumbnails').getElementsByTagName('img');
		for (var x = 0, newImage = null; x < images.length; x++)
			{
			this.imageCache[this.imageCache.length] = new Image();
			this.imageCache[this.imageCache.length-1].src = images[x].src.replace('furnitureThumb', 'large').replace(/\&amp\;/g, '&');
			}
		}
	

	/**
	* Changes the product image photo
	*
	* @param		obj		The anchor clicked on
	*/
	this.changePhoto = function(obj)
		{
		setTimeout("document.getElementById('productFullsize').src = '" + obj.getElementsByTagName('img')[0].src.replace('furnitureThumb', 'large').replace(/\&amp\;/g, '&') + "';", 50);
		}
	}

