/**
* Assign the view handler
*/

viewHandler = Home;

/**
* Creates a new object with methods used by the Home page
*
* @author				Matt Gifford
* @copyright			2008 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);

		// Add animation to page elements
		this.initThumbnailAnimation();
		this.initFeedsAnimation();
		}


	/**
	* Adds the event handlers to fade in/out the thumbnails
	*/
	this.initThumbnailAnimation = function()
		{
		// Process the images
		for (var x = 9; 0 < x; x--)
			{
			// Get the element
			var element = document.getElementById('homeFeatured' + x);

			// Add an unique reference id to the element
			element.setAttribute('animationId', 'id' + this.animationReferences.count++);

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

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

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

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


		// Add animation to footer logos

		// Get the element
		var element = document.getElementById('globalFooterLogos');
		YAHOO.util.Dom.setStyle(element, 'opacity', 0);
		element.style.visibility = 'visible';

		// Add an unique reference id to the element
		element.setAttribute('animationId', 'id' + this.animationReferences.count++);

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

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

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

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


	/**
	* Adds the event handlers to change the colour of links in the feeds section
	*/
	this.initFeedsAnimation = function()
		{
		var links = document.getElementById('homeFeeds').getElementsByTagName('a');
		for (var x = links.length-1; 0 <= x; x--)
			{
			// Check if this is an animated link
			if (links[x].className.indexOf('animate') != -1)
				{
				// Add an unique reference id to the element
				links[x].setAttribute('animationId', 'id' + this.animationReferences.count++);

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

					// Animate the link
					xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.ColorAnim(this, {color: { to: '#FFFFFF' }}, 0.3, YAHOO.util.Easing.easeBoth );
					xhtml.animationReferences[this.getAttribute('animationId')].animate();
					}

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

					// Animate the link
					xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.ColorAnim(this, {color: { to: '#cccccc' }}, 0.9, YAHOO.util.Easing.easeBoth );
					xhtml.animationReferences[this.getAttribute('animationId')].animate();
					}
				}
			}

		// Add an unique reference id to the element
		document.getElementById('globalHeaderTwitter').getElementsByTagName('p')[0].setAttribute('animationId', 'id' + this.animationReferences.count++);

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

			// Animate the link
			xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.ColorAnim(this, {color: { to: '#FFFFFF' }}, 0.3, YAHOO.util.Easing.easeBoth );
			xhtml.animationReferences[this.getAttribute('animationId')].animate();
			}

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

			// Animate the link
			xhtml.animationReferences[this.getAttribute('animationId')] = new YAHOO.util.ColorAnim(this, {color: { to: '#cccccc' }}, 0.9, YAHOO.util.Easing.easeBoth );
			xhtml.animationReferences[this.getAttribute('animationId')].animate();
			}
		}
	}
