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



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

		// Setup the slide animation
		this.slides = {
			current: 1,
			fade: 1000,
			interval: 8000,
			count: dojo.query("#homeIntro .slide").length,
			timer: null
			}

		// Start the animation
		this.slides.timer = setTimeout("xhtml.slides.timer = setInterval(\"xhtml.animateSlides();\", xhtml.slides.interval);", 5000);
		}
	

	/**
	* Animates the homepage slides
	*
	* @param		slide		The slide to jump to (optional)
	*/
	this.animateSlides = function(slide)
		{
		// 1. Get new slide values
		if (arguments.length && slide <= xhtml.slides.count)
			{
			// Jump to a particular slide
			xhtml.slides.current = slide;
			var previousSlide = slide;

			// Reset the timer (since we're jumped to a slide mid step)
			clearInterval(xhtml.slides.timer);
			clearTimeout(xhtml.slides.timer);
			}
		else
			{
			// Advance the current slide
			var previousSlide = xhtml.slides.current;
			xhtml.slides.current = (xhtml.slides.count < ++xhtml.slides.current ? 1 : xhtml.slides.current);
			}

		// 2. Build stacking styles
		var settings = [];
		for (var x = xhtml.slides.count; 0 < x; x--)
			{
			// Hide unused slides at the bottom of the stack
			settings[x] = {
				zIndex: 100,
				opacity: 0
				}
			}

		// Set the previous slide below the new current slide
		settings[previousSlide].zIndex = 105;
		settings[previousSlide].opacity = 1;

		// Put the new current slide on top
		settings[xhtml.slides.current].zIndex = 110;

		// 3. Set stacking the new styles
		for (var x = settings.length-1; 0 < x; x--)
			{
			dojo.style(document.getElementById('homeIntroSlide' + x), 'opacity', settings[x].opacity);
			dojo.style(document.getElementById('homeIntroSlide' + x), 'zIndex', settings[x].zIndex);
			dojo.style(document.getElementById('homeIntroSlide' + x), 'visibility', 'visible');
			}
		
		// 4. Change the current slide
		if (arguments.length && slide <= xhtml.slides.count)
			{
			// Reset the timer (since we're jumped to a slide mid step)
			xhtml.slides.timer = setInterval("xhtml.animateSlides();", xhtml.slides.interval);
			}
		else
			{
			// Fade in new slide
			dojo.fadeIn({ node: document.getElementById('homeIntroSlide' + xhtml.slides.current), duration: xhtml.slides.fade }).play();
			}
		}
	}
