/**
 * @author samuelme
 */



var HomePage = function(){
	
	//private vars
	var $vidHolder = $('<div id="videoHolder">	<div id="message"><h1>Flash Player Upgrade</h1><p>Our web site is best optimized for browsers with the Adobe Flash Player 9.0.115.0 or higher.</p><p>Once the Flash player is installed, refresh this page to view the optimized content.</p><p><a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Download Flash Player Upgrade</a></p></div></div>')
	var checkInit = 0;
	//public methods
	
	
	return {
		init : function(){
			checkInit = 0;
		},
		removeVideo : function(){
			$('#videoHolder').remove();
		},
		showVideo : function(){
			
			setupFlash();
		},
		gotoSect : function(){
			gotoSection();
		},
		checkInterval : function(){
			if(Alliance.isFlashReady() == true){
				
				gotoSection();
				
				setTitle();
				
				clearInterval(checkInit);
			}
			debug("Alliance.isFlashReady(): "+Alliance.isFlashReady());
		}
	}
	
	
	
	//private methods
	function setupFlash(){

			if ($('#videoHolder').size() <= 0) {
				
				$vidHolder.appendTo('#contentHolder');
				
				var so = new SWFObject("swf/alliance_main.swf", "alliance", "100%", "100%", "9.0.115", "#000000");
				
				so.addVariable("test_case", test_case);
				
				so.addParam("allowScriptAccess", "always");
				
				so.addParam("wmode", "transparent");
				
				so.write("videoHolder");
				
			}
			$('#videoHolder').show();
			clearInterval(checkInit);
			checkInit =  setInterval ( 'HomePage.checkInterval()', 600 );
	}
	
	function gotoSection(){
		
		if (Alliance.getSection() == 'facility') {
			
			try {
				
				Alliance.getMovie().showIntro();
				debug('showtinro');
			} 
			
			catch (e) {
					
				debug(e);
			}
		}else{
			
			try {
				
				Alliance.getMovie().showGame()
				debug('showGame');
				
			} 
			catch (e) {
				
				debug(e);
			}
			
		}
		
	}
	
	function setTitle(){
		
		if(Alliance.getSection() == 'facility'){
			
			SWFAddress.setTitle("This Is Reality | Watch the TV Spot");
			
		}else{
			
			SWFAddress.setTitle("This Is Reality | Reality Fly By");
		}
	}
	
	
	function debug($obj) {
		if (window.console && window.console.log)
			window.console.log($obj);
	};
	
}();
