

/*********************** Game Login Functionality ******************/
/*********** in addition to fflogin.js, unityobject.js *************/


/************ Resolution Detection **********/
	var myWidth = 0;
	var myHeight = 0;
	if (typeof window.innerWidth == 'number') {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientWidth) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
/************ Browser Detection **********/
	var isWin				= 0;
	var isMac				= 0;
	var isOtherOs			= 0;
	var agentOs				= navigator.platform.toLowerCase();
	if(agentOs.indexOf('win') != -1) isWin = 1;
	else if(agentOs.indexOf('mac') != -1) isMac = 1;
	else( isOtherOs = 1);

	var isIE				= 0;
	var isMoz				= 0;
	var isOpera				= 0;
	var isSafari			= 0;
	var isChrome			= 0;
	var agentApp			= navigator.userAgent.toLowerCase();
	if(agentApp.indexOf('firefox') != -1) isMoz = 1;
	else if(agentApp.indexOf('msie') != -1) isIE = 1;
	else if(agentApp.indexOf('opera') != -1) isOpera = 1;
	else if(agentApp.indexOf('safari') != -1) isSafari = 1;
	else if(agentApp.indexOf('chrome') != -1) isChrome = 1;
	else( isMoz = 1);
/************ Browser Detection **********/
	
	
// Redirects
function gotoLogin(){
	document.location.href="http://www.cartoonnetwork.com/accounts/";
}
function gotoLogout(){
	document.location.href="http://www.cartoonnetwork.com/accounts/";
}
function gotoAccount(){
	document.location.href="http://www.cartoonnetwork.com/accounts/";
}
function gotoMod(){
	document.location.href="http://www.cartoonnetwork.com/accounts/";
}
function gotoBeta(){
	document.location.href="http://fusionfall.cartoonnetwork.com/play/";
}

// PopUp Windows & Controllers
function go(url){
	window.opener.location.href = url; 
} 
function goFocus(url){
	window.opener.focus();
	window.opener.location.href = url; 
} 

function imgSwitch(name,path) {
	document.getElementById(name).src=path;
}
function openGuide(){
		guideWindow = window.open("http://fusionfall.cartoonnetwork.com/game/gameguide.html", "gameguide", "outerWidth=620,outerHeight=768,width=620,height=768,left=5,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=yes");
		guideWindow.focus();
}
function openHelp(){
	document.getElementById("trouble").style.display = (document.getElementById("trouble").style.display == "none" ? "block" : "none");
}
function closeHelp(){
	document.getElementById("trouble").style.display = "none";
}
function openOverlay(){
	document.getElementById("fader").style.display = "block";
	document.getElementById("trouble2").style.display = (document.getElementById("trouble2").style.display == "none" ? "block" : "none");
}
function closeOverlay(){
	document.getElementById("fader").style.display = "none";
	document.getElementById("trouble2").style.display = "none";
}
function openNoFlash(){
	clientWindow = window.open("noflash.php","","outerWidth=1024,outerHeight=757,width=1024,height=757,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=yes");
	downloadWindow.focus();
}
function exitGame(){
	window.close();
	thanksLoad();
}
function logoutAccount(){
	window.close();
	CartoonMSIB.logOut();
	thanksLoad();
}


/* used to open the Thanks & Survey page on popup close */
function f_open_window_max( aURL, aWinName ){
   var wOpen;
   var sOptions;

   sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}
function thanksLoad() {
	//alert ("i'm running!");
	if (window.opener && window.opener.open && !window.opener.closed) {
		opener.location=("http://fusionfall.cartoonnetwork.com/play/thanks.php");
	}else {
		f_open_window_max('http://fusionfall.cartoonnetwork.com/play/thanks.php', '');
		//window.open ("http://www.fusionfall.com/contact/survey.html",'','fullscreen=yes');
	}
}
function surveyLoad() {
	//alert ("i'm running!");
	if (window.opener && window.opener.open && !window.opener.closed) {
		opener.location=("../contact/survey.html");
	}
	else {
		f_open_window_max('http://fusionfall.cartoonnetwork.com/contact/survey.html', '');
		//window.open ("http://www.fusionfall.com/contact/survey.html",'','fullscreen=yes');
	}
}

function loginGameFlow(){
	CartoonMSIB.loadMSIB('msib_login', 'http://' +serverUrl+ '.cartoonnetwork.com/accounts/login.html?pid=cn.fusionfall'); 
}



// Broswer Resizing & Sniffing Code
function openUnity(){
//	clientWindow = window.open("http://www.fusionfall.com/game/beta2.php","","outerWidth=1023,outerHeight=661,width=1023,height=661,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=no");
//	clientWindow = window.open("http://www.fusionfall.com/game/beta2.php","","outerWidth=1023,outerHeight=661,width=1023,height=661,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=no");
	
	
//	if(isChrome > 0){
//		document.location.href="http://fusionfall.cartoonnetwork.com/play/index_unsupported.php";	
//	}

	//opens a div overlay with popup message, for popup blockers;
	openOverlay();
	
	//
	if (screen.availWidth > 1280){
		popup_width			= 1280; //Math.floor(screen.width*.80);
		popup_height		= 760;//Math.floor(screen.height*.90);
		//alert(popup_width);
		//alert(popup_height);
		clientWindow = window.open("intro.php","gamewindow","width=" +popup_width+ ",height=" + popup_height+ ",menubar=no,scrollbars=no,toolbar=no,status=no,resizable=yes");
		//clientWindow = window.open("intro.php","gamewindow","innerHeight=684,innerWidth="+popup_width+",height=684,width="+popup_width+",menubar=no,scrollbars=no,toolbar=no,status=no,resizable=yes");
	}else if (screen.availWidth > 1024 && screen.availWidth <= 1280){
		clientWindow = window.open("intro.php","gamewindow","outerWidth=1080,outerHeight=757,width=1080,height=757,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=yes");
	}else{
		clientWindow = window.open("intro.php","gamewindow","outerWidth=1024,outerHeight=757,width=1024,height=757,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=yes");
	}	
	clientWindow.focus();
}

/*
//function checkWindow(){
	if(true == window.closed){
    	alert('Window closed');
 		}else{
    	alert('Window open');
 	}
//}
*/
