/**
* Assign the view handler
*/

viewHandler = Home;

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

	var _instance = this;
	this.passportHideTimeout = null;
	this.videoLock = false;

	this.flashVideoFilenames = {
		'person1': 'Daina 8 Second.flv',
		'person2': 'Javier 8 Second.flv',
		'person3': 'Javier 8 Second.flv',
		'person4': 'Monica 8 Second.flv',
		'person5': 'Nathan 8 Second.flv'
		};


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

		// 1. Add event handlers to people
		for (var x = 1; x < 6; x++)
			{
			// Add event handlers to show and hide the passports
			document.getElementById('person' + x).onmouseover = __eventHandlerPersonOver;
			document.getElementById('person' + x).onclick = __eventHandlerPersonClick;
			document.getElementById('passport' + x).onmouseover = __eventHandlerPassportOver;
			document.getElementById('passport' + x).onmouseout =__eventHandlerPassportOut;

			// Add the show/hide fullsize image event handlers to the thumbnails
			var imgs = document.getElementById('passport' + x).getElementsByTagName('img');
			for (var y = 0; y < imgs.length; y++)
				{
				if (imgs[y].className.indexOf('thumbnail') != -1)
					{
					imgs[y].onmouseover = __eventHandlerThumbnailOver;
					imgs[y].onmouseout = __eventHandlerThumbnailOut;
					}
				}
			}
		}


	/**
	* Hides the specified passport
	* @param		id			The passport id
	*/
	this.hidePassport = function(id)
		{
		document.getElementById('passport' + id).className = 'passport hidden';
		document.getElementById('person' + id).className = '';
		}


	/**
	* Adds the flash from the specified passport
	*
	* @param		id			The id of the passport the flash relates to
	*/
	this.openVideo = function(id)
		{
		if (xhtml.videoLock == true)
			{
			return;
			}

		// Add the flash container
		var container = document.createElement('div');
		container.id = 'passport'+id+'flashContainer';
		document.getElementById('passport'+id+'flash').appendChild( container );
		document.getElementById('passport'+id+'flash').style.visibility = 'visible';

		// Display the flash video
		var so = new SWFObject("test/Rewire 8 second test.swf", "rewire", "330", "250", "8", "#000000");
		so.addParam("wmode", "window");
		so.addParam("allowScriptAccess", "sameDomain");
		switch(id) {
			case 1:
				so.addVariable("filename", "Daina 8 Second.flv");		
			break;
			case 2:
				so.addVariable("filename", "Javier 8 Second.flv");		
			break;
			case 4:
				so.addVariable("filename", "Monica 8 Second.flv");		
			break;
			case 5:
				so.addVariable("filename", "Nathan 8 Second.flv");		
			break;
			}

		so.addVariable("passport", id);
		so.write('passport'+id+'flashContainer');

		// Lock the UI
		this.videoLock = true;
		}


	/**
	* Removes the flash from the specified passport
	*
	* @param		id			The id of the passport the flash relates to
	*/
	this.closeVideo = function(id)
		{
		setTimeout("document.getElementById('passport"+id+"flashContainer').parentNode.removeChild( document.getElementById('passport"+id+"flashContainer')); document.getElementById('passport"+id+"flash').style.visibility = 'hidden'; xhtml.videoLock = false;", 250);
		}



	// Step 3. Define Private Methods

	/**
	* Event Handler:  Displays the passport on mouseover of a person
	*/
	function __eventHandlerPersonOver()
		{
		try
			{
			if (xhtml.videoLock == true)
				{
				return;
				}
			clearTimeout(xhtml.passportHideTimeout);
			for (var x = 1; x < 6; x++)
				{
				document.getElementById('person' + x).className = '';
				document.getElementById('passport' + x).className = 'passport hidden';
				}

			this.className = 'active';
			document.getElementById(this.id.replace('person', 'passport')).className = 'passport';
			}
		catch (err) {}
		}


	/**
	* Event Handler: Closes the playing video on click
	*/
	function __eventHandlerPersonClick()
		{
		try
			{
			// Close the playing video
			if (xhtml.videoLock == true)
				{
				xhtml.closeVideo();
				}

			clearTimeout(xhtml.passportHideTimeout);
			for (var x = 1; x < 6; x++)
				{
				document.getElementById('person' + x).className = '';
				document.getElementById('passport' + x).className = 'passport hidden';
				}

			this.className = 'active';
			document.getElementById(this.id.replace('person', 'passport')).className = 'passport';
			}
		catch (err) {}
		}


	/**
	* Event Handler: Cancels the hide timeout while over a passport
	*/
	function __eventHandlerPassportOver()
		{
		try
			{
			clearTimeout(xhtml.passportHideTimeout);
			}
		catch (err) {}
		}


	/**
	* Event Handler: Queues the hide timeout when leaving a passport
	*/
	function __eventHandlerPassportOut()
		{
		try
			{
			if (xhtml.videoLock == true)
				{
				return;
				}
			clearTimeout(xhtml.passportHideTimeout);
			xhtml.passportHideTimeout = setTimeout("xhtml.hidePassport(" + this.id.replace('passport', '') + ");", 250);
			}
		catch (err) {}
		}


	/**
	* Event Handler: Displays the larger image
	*/
	function __eventHandlerThumbnailOver()
		{
		document.getElementById(this.id.replace('thumbnail', 'fullsize')).style.visibility = 'visible';
		}


	/**
	* Event Handler: Hides the larger image
	*/
	function __eventHandlerThumbnailOut()
		{
		document.getElementById(this.id.replace('thumbnail', 'fullsize')).style.visibility = 'hidden';
		}
	}



/**
* Global Function for Flash Callback
*/
function rewire_DoFSCommand(param1)
	{
	xhtml.closeVideo();
	}
