// set global variables
var showMovie = true; // show flash or not based on size of window 
var firstTime = true; // first time run 
var shownLast; // was flash shown last resize
var initialFlashContent; // hold flash content 
var currentInnerHTML; // innerHTML of showing Div 
/*
var emailImageOff  = new Image();
var emailImageOn= new Image();
var sendImageOff= new Image();
var sendImageOn= new Image();
var shopImageOff= new Image();
var shopImageOn= new Image();

emailImageOff.src = "../images/landingpage/emails_off.jpg";
emailImageOn.src = "../images/landingpage/emails_on.jpg";
sendImageOff.src = "../images/landingpage/send_off.jpg";
sendImageOn.src = "../images/landingpage/send_on.jpg";
shopImageOff.src = "../images/landingpage/shop_off.jpg";
shopImageOn.src = "../images/landingpage/shop_on.jpg";
*/
var theWidth, theHeight; // actual dimensions of inner window 


// run sizing function when laoded 
hideNav();
setBottomDiv();
writeEmailMessage()


//rollover function 
function switchImage(id, newImage){

	document.getElementById(id).src = newImage.src;

}

// function to open a new window centered 
// example use: cWindow('http://ebm.cheetahmail.com/r/regf2?a=0&aid=949559453&n=600',350,360)
var win = null;
function cWindow(page,w,h)
{
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
			var settings = 'height=' + h + ',';
			settings += 'width=' + w + ',';
			settings += 'top=' + wint + ',';
			settings += 'left=' + winl + ',';
			settings += 'statusbar=0';
				win = window.open(page,name,settings);

}

// sizing function first run 
function setBottomDiv(){

	setDimensions();

	theHeight = ((theHeight *1) + bottomNavHeight);
	
	writeStyle();

	showTheMovie();

	writeContent();
	
}


// window sizing function after first run
function resetBottomDiv(){

	setDimensions();

	theHeight = ((theHeight *1) + bottomNavHeight);

	showTheMovie();
	
	writeContent();


}

// find inner dimensions of the window
function setDimensions() {

	// Window dimensions:
	if (window.innerWidth) {
	theWidth=window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
	theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) {
	theWidth=document.body.clientWidth;
	}
	if (window.innerHeight) {
	theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
	theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) {
	theHeight=document.body.clientHeight;
	}

	//testing 
	//alert (currentHeight);
	//alert (currentWidth);

}

// determine if we show the movie 
function showTheMovie(){
	//minimum dimensions 
	if (theHeight <= requiredHeight || theWidth <= requiredWidth) {
	
		showMovie = false; 
	
	}
	else {
		showMovie = true; 
	}
	
	
}

//write sttyle for flash content based on height 
function writeStyle(){

	var flashStyle = '<style type="text/css">';
	flashStyle += '#flashcontent {';
	flashStyle += 'height:' + ((theHeight *1) + bottomNavHeight) +'px; ';
	flashStyle += 'color: #ffffff;';
	flashStyle += 'font-family: Arial, Helvetica, sans-serif; ';
	flashStyle += 'font-size: 12px; ';
	flashStyle += 'margin-top: -' + bottomNavHeight + 'px; ';
	flashStyle += '}\n';
	flashStyle += '</style>';
	
	document.write (flashStyle);

}

// show flash or alternate content with correct error 
function writeContent(){
	
	//show the flash 
	if (showMovie){
		
		//and we are already showing the movie
		if (shownLast) {
			document.getElementById('flashcontent').style.height = theHeight + "px";
		}
		// else we are not currently showing the movie
		else {
			
			document.getElementById('flashcontent').style.height = theHeight + "px";
			so.write("flashcontent");
			currentInnerHTML = document.getElementById('flashcontent').innerHTML;
			shownLast = true;
		
		}
	}
	//don't show the flash
	else {
		var content = "";
		content +='<div id="stage" class="center">';
        content +='<img src="' + imageLocation + otherImagesLocation + '/TBLlogo_noFlash.jpg" alt="" /><br /><br />';
		
		//if screen width and height are ok, but the browser is too small 
		if ((screen.width>=(reqScreenWidth*1)) && (screen.height>=(reqScreenHeight*1)))
		{

			content += tooSmall;
		
		}
		//screen height or width not large enough
		else {
		
			content += screenTooSmall;
		
		}
		document.getElementById('flashcontent').innerHTML = content;
		shownLast = false; 

	}

}

//function to maximize window when error message is clicked 
function maximiser()
{
	/*
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
	var currentLocation = window.location.href;
	*/
	top.window.moveTo(0,0); 
	if (document.all || document.getElementById) 
   	{ 
		top.window.resizeTo(screen.availWidth,screen.availHeight); 
	} 
	else if (document.layers || document.getElementById) 
	{ 
	   if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth)
		{ 
		   top.window.outerHeight = top.screen.availHeight; 
		   top.window.outerWidth = top.screen.availWidth; 
		} 
	} 

}

//writes email message on footer
function writeEmailMessage(){

	document.getElementById('emailMessageLink').href = emailMessage;
	document.getElementById('shopLink').href = shopMessage;
	document.getElementById('sendToAFriendLink').href = sendToAFriendMessage;
	
	document.getElementById('emailMessageLinkEK').href = emailMessage;
	document.getElementById('shopLinkEK').href = shopMessage;
	document.getElementById('sendToAFriendLinkEK').href = sendToAFriendMessage;
	
	//document.write(emailMessage);
	
}

function launchGame(){

	launchLyteboxLink();

}

function hideNav(){
	
	  var curLocation = document.location + " ";
      //alert(curLocation.indexOf("Hello"));
      if (curLocation.indexOf("noNav=true") != -1) {
     
          document.getElementById('bottomNav').style.display = "none";
         
     
      }

}


