/**
* Assign the view handler
*/

viewHandler = Home;

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

	var _instance = this;
	this.animationReferences = { count: 1 };



	// 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);

		// Init the story event handlers
		this.initStories();

		// Init animation on bottle description
		this.initBottleAnimation();

		// Init animation on organic description
		this.initOrganicAnimation();
		}
	
	
	/**
	* Sets up the swapping of the story items
	*/
	this.initStories = function()
		{
		var storyLinks = document.getElementById('homeStories').getElementsByTagName('ul')[0].getElementsByTagName('a');
		for (var x = 0; x < storyLinks.length; x++)
			{
			storyLinks[x].onmouseover = function()
				{
				// Hide the inactive menu, story and backgrounds
				var storyLinks = document.getElementById('homeStories').getElementsByTagName('ul')[0].getElementsByTagName('a');
				for (var y = 0; y < storyLinks.length; y++)
					{
					storyLinks[y].className = '';
					document.getElementById('storyItem' + (y + 1)).className = 'hidden';
					document.getElementById('homeBackgrounds' + (y + 1)).className = 'hidden';
					}
				
				// Make the active story, menu and background visible
				this.className = 'active';
				document.getElementById(this.parentNode.id.replace('storyMenu', 'storyItem')).className = '';
				document.getElementById(this.parentNode.id.replace('storyMenu', 'homeBackgrounds')).className = '';
				}
			}
		}


	/**
	* Sets up the animation of the bottle description
	*/
	this.initBottleAnimation = function()
		{
		var bottleActive = document.getElementById('homeBottleActive');

		// Set the initial opacity on the definition
		YAHOO.util.Dom.setStyle(bottleActive, 'opacity', 0);
		YAHOO.util.Dom.setStyle(bottleActive, 'visibility', 'visible');

		// Add the same unique reference id to both the elements
		bottleActive.setAttribute('animationId', 'id' + this.animationReferences.count++);

		// Add event handler for mouse over
		bottleActive.onmouseover = function()
			{
			// Try to stop any existing animation on this object
			try { xhtml.animationReferences[this.getAttribute('animationId')].stop(false); } catch (err) {}

			// Animate the definition
			xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.Anim(this, {opacity: { to: 1 }}, 0.3, YAHOO.util.Easing.easeBoth );
			xhtml.animationReferences[this.getAttribute('animationId')].animate();
			}

		// Add event handler for mouse out
		bottleActive.onmouseout = function()
			{
			// Try to stop any existing animation on this object
			try { xhtml.animationReferences[this.getAttribute('animationId')].stop(false); } catch (err) {}

			// Animate the definition
			xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.Anim(this,  {opacity: { to: 0 }}, 0.9, YAHOO.util.Easing.easeBoth );
			xhtml.animationReferences[this.getAttribute('animationId')].animate();
			}
		}


	/**
	* Sets up the animation of the organic description
	*/
	this.initOrganicAnimation = function()
		{
		var organicActive = document.getElementById('homeOrganicActive');

		// Set the initial opacity on the definition
		YAHOO.util.Dom.setStyle(organicActive, 'opacity', 0);
		YAHOO.util.Dom.setStyle(organicActive, 'visibility', 'visible');

		// Add the same unique reference id to both the elements
		organicActive.setAttribute('animationId', 'id' + this.animationReferences.count++);

		// Add event handler for mouse over
		organicActive.onmouseover = function()
			{
			// Try to stop any existing animation on this object
			try { xhtml.animationReferences[this.getAttribute('animationId')].stop(false); } catch (err) {}

			// Animate the definition
			xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.Anim(this, {opacity: { to: 1 }}, 0.3, YAHOO.util.Easing.easeBoth );
			xhtml.animationReferences[this.getAttribute('animationId')].animate();
			}

		// Add event handler for mouse out
		organicActive.onmouseout = function()
			{
			// Try to stop any existing animation on this object
			try { xhtml.animationReferences[this.getAttribute('animationId')].stop(false); } catch (err) {}

			// Animate the definition
			xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.Anim(this,  {opacity: { to: 0 }}, 0.9, YAHOO.util.Easing.easeBoth );
			xhtml.animationReferences[this.getAttribute('animationId')].animate();
			}
		}
	}
