

/*********************** 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="https://audience.fusionfall.com/ff/ffLogin.do";
	document.write("<p class=login>You must be logged in to access <em>FusionFall</em>.  Please <a href='https://audience.fusionfall.com/ff/login.do'>login or register</a> here.</p>");
}
function gotoLogout(){
	document.location.href="https://audience.fusionfall.com/ff/logout.do";
}
function gotoAccount(){
	document.location.href="https://audience.fusionfall.com/ff/regwall/accountAdmin.do";
}
function gotoMod(){
	document.location.href="http://www.fusionfall.com/play/index.php";
}
function gotoBeta(){
	document.location.href="http://www.fusionfall.com/play/intro.php";
}

// 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://www.fusionfall.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();
	surveyLoad();
}
function logoutAccount(){
	window.close();
	go("https://audience.fusionfall.com/ff/logout.do");
}


/* 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://www.fusionfall.com/play/thanks.php");
	}else {
		f_open_window_max('http://www.fusionfall.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://www.fusionfall.com/contact/survey.html', '');
		//window.open ("http://www.fusionfall.com/contact/survey.html",'','fullscreen=yes');
	}
}



// Broswer Resizing & Sniffing Code
function openUnity(){
/*
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
		alert(this.browser);
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
*/

/* temp
	if (navigator.platform == "MacPPC") {
//		alert("MacPPC");
//		document.location.href="http://www.fusionfall.com/play/index_unsupported.php";
		return;
	}
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if (is_chrome) {
	//	alert("Chrome");
	// temp	document.location.href="http://www.fusionfall.com/play/index_unsupported.php";
		return;
	}
temp */

		
/*		if (BrowserDetect.version="8") {
		document.location.href="http://www.fusionfall.com/game/index_unsupported.php";
		return;
		}
		var browser = navigator.appVersion;
	if (browser.indexOf('MSIE 7.0') > -1) {
		if (!XDomainRequest) {
		alert("IE 6");
		//document.location.href="http://www.fusionfall.com/game/index_unsupported.php";
		return;
		}
}
*/
//	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://www.fusionfall.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');
 	}
//}
*/