/***********************************************
Module Animation Methods
***********************************************/
	
	
	var currentModule;
	var oldModule;
	
	
	// this is the initial module animation
	function initialModuleAnimation()
	{
		currentModule = 1;
		oldModule = 1;
		//$("#homeModule"+currentModule).show();
		//$("#homeModule"+currentModule).animate({marginTop: "0px"}, 300 , "linear", function(){animateInDone();} );
  	}
	
	// hides the stale module, and shows and animates the new module
	function hideDone(old, current)
	{		
		$("#homeModule"+old).hide();
		$("#homeModule"+current).show();
		$("#homeModule"+current).animate({marginTop: "0px"}, 300 , "linear", function(){animateInDone();} );
	}
	
	function hideAnimation(old, current)
	{
		$("#homeModule"+old).animate({marginTop: "300px"}, 
		 	300, 
		 	"linear", 
		 	function(){hideDone(old,current);		
	  	});
	}
	
	function closeAnimation()
	{
		$("#homeModule"+currentModule).animate({marginTop: "300px"}, 
		 	300, 
		 	"linear"
	  	);
	}
	
	
	// call back after hideAnimation is done...
	function animateInDone()
	{
		
	}
	
/***********************************************
Trailer
***********************************************/

	
	var flashvars = {
		src: "",
		//loadImage:"/images/videos/videoBG_home.jpg",	
		//embed: "",
		//link: "http://www.starzanimation.com/aboutus/whoweare/culture.html",
		//mode: "overlay",
		//scaleMode: "fit",
		themeColor: "972B28",	// Yes,Virginia! Red Hair color
		autostart:"true"
	};
	
	var params = {
		wmode:"normal",
		allowScriptAccess: "always",
		allowFullScreen: "true",
		menu: "false"
	};
	
	var attributes = {
		
	};
	
	function embedTrailer()
	{	
		swfobject.embedSWF("/StarzAnimation/swf/SAVideoPlayer.swf", "SAVideoPlayer", 
                                        "700", "404", "10",
                                        "/StarzAnimation/swf/expressInstall.swf", flashvars, params, attributes );
	}
		
	
	function trailerOpenComplete()
	{
	   newSource(siteTrailerUrl);
	}
	
	function trailerCloseComplete()
	{
		newSource('');
	}
	
	  
  /*******************************
  Set the video of the flash filed
  *******************************/
  function newSource(str){
	 getFlashMovieObject("SAVideoPlayer").setNewSource(str);
    //$('#SAVideoPlayer').setNewSource(str);
  }
  
  function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
	
	
/***********************************************
Background Fading
***********************************************/	
	
	// fade time
	var TIMEOUT = 8000;
	
	function newImageBatch()
	{
		$("#slideshow1 img:first").show();
		$('#slideshowTemp').fadeOut(2000, function(){
			$("#slideshow1").cycle({
				timeout:  TIMEOUT
			});
		});
	}
	
	
/***********************************************
Home hide a delay
***********************************************/
function hideHomeItems()
{
	closeAnimation();
	$('#homeText').hide();
	$('#homeModuleHolder').hide();
	$('#homeModuleButtonsList').hide();

	//fadeInHomeItems();
}

function fadeInHomeItems()
{
	newImageBatch();
	$('#homeText').show();
	$('#homeModuleHolder').show();
	$('#homeModuleButtonsList').show();
}

/***********************************************
JQuery Ready
***********************************************/
  
  $(document).ready(function(){
	if(swfobject.getQueryParamValue("bypasssplash") != "true")
  	{
		hideHomeItems();
		setTimeout ( "fadeInHomeItems()", 4000 );
  	}
	else
	{
		fadeInHomeItems();
	}
	
	
	initialModuleAnimation();
	
	// Module 1 Clicked
	$("#homeModuleButton1").mouseover(function () {
      oldModule = currentModule;
	  currentModule = 1;
	  hideAnimation(oldModule, currentModule);
	});
	 
	 // Module 2 Clicked
	$("#homeModuleButton2").mouseover(function () {
      oldModule = currentModule;
	  currentModule = 2;
	  hideAnimation(oldModule, currentModule);
	});
	 
	 // Module 3 Clicked
	$("#homeModuleButton3").mouseover(function () {
      oldModule = currentModule;
	  currentModule = 3;
	  hideAnimation(oldModule, currentModule);
	});
	
	
	$("#trailerButton").click(function () {
		$("#trailerContainer").slideToggle("normal",trailerOpenComplete);
		$('#slideshow1').cycle('pause');
		hideHomeItems();
		
		
	});
	
	$("#trailerCloseButton a").click(function () {
		$("#trailerContainer").slideToggle("normal",trailerCloseComplete);
		$("#slideshow1").cycle('resume');
		fadeInHomeItems();
	});
	
	$(".moduleCloseBtn").click(function () {
		closeAnimation();
	});
	embedTrailer();
	
   
  });
  

