var myTab = "undefined";
var mySubPage = "undefined";


function refresh() {

var now = new Date();
var hour = now.getHours();
var sURL = unescape(window.location.pathname);

	if (hour >= 3 && hour <= 4)
	{
		//alert("refresh");
		window.location.href = sURL;
	}

}

var webKiosk = (function() {


	function Setting(name) {
		this.name = name;
	}


	Setting.prototype.changeTab = function (myNewTab) {
		var myTab = myNewTab;
		//alert(myTab);
	}

	Setting.prototype.changeSubPage = function (myNewSubPage) {
		var mySubPage = myNewSubPage;
		//alert(mySubPage);		
	}


	Setting.prototype.maxWindow = function() {
	
		var agree = confirm('GreenTouchscreen is now maximizing your browser window.');

		if (agree)
		{
			
			window.moveTo(0,0);
		
			if (document.all)
			{
				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 = screen.availHeight;
					top.window.outerWidth = screen.availWidth;
				} 
		
			}

		}
			
	}






	Setting.prototype.fullScreenWindow = function () {

		alert('If you are using Windows and running Internet Explorer press the F11 key on your keyboard to enabled and disable TRUE kiosk mode.  \r(Note: You may need to right click the top menu bar and select the Auto-Hide option)\r\rIf you are using Windows and Firefox press the F11 key on your keyboard to enable.\r(Note: You can not view TRUE kiosk mode unless you download a third party extension, we recommend the Almost Full Screen extension)\r\rIf you are using a Mac and running Safari you can only run kiosk mode with a third-party extension, we recommend the Saft extension.\r\rClick the OK button below before attempting to enter Full Screen Kiosk Mode.');

				
	}






	Setting.prototype.changeWindowSize = function (myWidth, myHeight) {

		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			//works for firefox
			top.window.innerHeight = myHeight;
			top.window.innerWidth = myWidth;
		} else {
			//works for IE
			//IE is dumb and needs an alert box prior to calling the resizeTo function for some reason
			var agree = confirm("GreenTouchscreen is now resizing your browser window to " + myWidth + " x " + myHeight + " pixels.");			
			if (agree)
			{
				window.resizeTo(myWidth, myHeight); //resize IE
				
				var myWidth2 = document.body.clientWidth; //grab actual height & width size of browser (will be smaller due to horizontal toolbars)
				var myHeight2 = document.body.clientHeight;
								
				var myWidthOffSet = myWidth - myWidth2; //subtract desired width from the actual size to find how "off" IE is
				var myHeightOffSet = myHeight - myHeight2; 

				var myWidthWithOffset = myWidth + myWidthOffSet; //add that offset to desired width
				var myHeightWithOffset = myHeight + myHeightOffSet;

				window.resizeTo(myWidthWithOffset, myHeightWithOffset); //resize again so IE will render correctly

			}

		}	
	}






	Setting.prototype.setMovieSize = function (browserWidth,browserHeight,movieWidthRatio,movieHeightRatio,borderSize) {

		var browserWidthRatio = (movieHeightRatio * browserWidth) / browserHeight;
		//alert("movieHeightRatio:" + movieHeightRatio + " browserWidth:" + browserWidth + " browserHeight:" + browserHeight + " browserWidthRatio" + browserWidthRatio);
		
			if (browserWidthRatio <= movieWidthRatio)
			{
				//height is larger
				//alert("height=larger");
				var movieWidthDim = browserWidth - (borderSize * 2);
				var movieHeightDim = ((movieWidthDim * movieHeightRatio) / movieWidthRatio);
				//alert("movieWidthDim:" + movieWidthDim + " movieHeightDim:" + movieHeightDim );
			} else {
				//width is larger
				//alert("width=larger");
				var movieHeightDim = browserHeight - (borderSize * 2);
				var movieWidthDim = ((movieHeightDim * movieWidthRatio) / movieHeightRatio);
			}
		
		//prepares to center movie vertically
		var movieHeightOffset = (browserHeight - movieHeightDim) / 2;
		
		var myArray = new Array();
		myArray[0] = movieWidthDim;
		myArray[1] = movieHeightDim;
		
		//alert(myArray[0] + " " + myArray[1]);
		
		//if (myWidthRatio == "16") //only center if 16:9 or 16:10
		//{
		myArray[2] = movieHeightOffset; //currently always center
		//}
			
		return myArray;

	}






	Setting.prototype.CSSMargin = function (marginNum) {
		document.body.style.margin = marginNum + "px";
	}




	Setting.prototype.CSSoffset = function (marginNum) {
		document.body.style.marginTop = marginNum + "px";
	}




	Setting.prototype.getSize = function (mySWF, myTab, mySubPage, kioskVarsAdditions) {

		if (typeof( window.innerWidth ) == 'number') {
			//Non-IE
			var myWidth = window.innerWidth;
			var myHeight = window.innerHeight;
			//alert("W:" + myWidth + "   " + "H: " + myHeight);
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			var myWidth = document.documentElement.clientWidth;
			var myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			var myWidth = document.body.clientWidth;
			var myHeight = document.body.clientHeight;
		}

		//alert(myTab + "myTab");
		//alert(myWidth);

		var kioskVars_Union=[];
		for (var key in kioskVars){
			kioskVars_Union[key] = kioskVars[key];
		}
		for (var key in kioskVarsAdditions){
			kioskVars_Union[key] = kioskVarsAdditions[key];
		}


		this.kioskSize(myWidth,myHeight,mySWF,kioskVars_Union,kioskParams,myTab,mySubPage); 
		
		if (document.getElementById('kiosk'))
		{
			document.getElementById('kiosk').focus();
		}
	}






	Setting.prototype.kioskSize = function(myWidth,myHeight,mySWF,kioskVars,kioskParams,myTab, mySubPage) {

		if (mySWF) //for screensaver
		{
			SWFmainKiosk = mySWF;
		}
		
		var myMovieSize = this.setMovieSize(myWidth,myHeight,myWidthRatio,myHeightRatio,SWFborderSize);
		var SWFwidth = myMovieSize[0];//movieWidthDim
		var SWFheight = myMovieSize[1];//movieHeightDim
		var SWFoffset = myMovieSize[2];//movieHeightOffset

		//if manual override of width/height & not the physical kiosk
		if (typeof( window[ 'mySWFwidth' ] ) != "undefined" && typeof( window[ 'mySWFheight' ] ) != "undefined" && !getQueryParamValue("isPhysicalKiosk")) {
			var SWFwidth = mySWFwidth;
			var SWFheight = mySWFheight;
			document.getElementsByTagName("html")[0].style.overflow = "auto";	//allows user to scroll if kiosk is tall

		}

		//call swfobject.js class
		var so = new SWFObject(SWFmainKiosk, SWFid, SWFwidth, SWFheight, SWFversion, SWFbgcolor, SWFexpressInstall);
//alert("SWFwidth: "+SWFwidth+" SWFheight:"+SWFheight);
		//document.getElementById('flashcontent').style.width = SWFwidth + "px";

	
		/*--- Begin Add additional parameters here ---*/
	
			for (var key in kioskParams)
			so.addParam(key, kioskParams[key]); //set these parameters in the config file
						  // alert('kioskSize:' + mySubPage);
			for (var key in kioskVars)
			//alert( key + " " + kioskVars[key] )
			so.addVariable(key, kioskVars[key]); //parse variables from the config file
			
			//set custom _root variables
			
			so.addVariable("myTab",myTab); //access _root.myTab
			so.addVariable("mySubPage",mySubPage); //access _root.mySubPage
			so.addVariable("currentKioskWidth",myWidth); //access _root.currentKioskWidth for Kiosk Setting Window
			so.addVariable("currentKioskHeight",myHeight); //access _root.currentKioskHeight for Kiosk Setting Window
			
			//grab specific _GET variables from broswer
			so.addVariable("isPhysicalKiosk", getQueryParamValue("isPhysicalKiosk")); //access _root.isPhysicalKiosk
			so.addVariable("kioskLocation", getQueryParamValue("kioskLocation")); //access _root.kioskLocation
			so.addVariable("tabNum", getQueryParamValue("tabNum")); //access _root.tabNum
			so.addVariable("pageTitle", getQueryParamValue("pageTitle")); //access _root.pageTitle
			so.addVariable("language", getQueryParamValue("language")); //access _root.pageTitle
			so.addVariable("referrer", getQueryParamValue("referrer"));
		   
		/*--- End Add additional parameters here ---*/	   
		so.write(SWFdivID);
		
		if (getQueryParamValue("isPhysicalKiosk"))
		{
			SWFborderSize = 0;
		}

		this.CSSMargin(SWFborderSize);

		if (SWFoffset) //if width != 16
		{
			this.CSSoffset(SWFoffset);
		}
		
		//this show the accessibility info and error info otherwise it remains hidden
		if(!so.write('flashcontent')){
		   document.getElementById('flashcontent').style.color = "fff";
		   document.getElementsByTagName('div')[1].style.color = "#000";
		   document.getElementsByTagName('div')[1].style.width = "100%";
		   document.getElementsByTagName('div')[1].style.background = "#9DC646";
		   document.getElementsByTagName('div')[1].style.border = "1px solid #000";	   
		   document.getElementsByTagName('a')[0].style.color = "#A5C8EE";
		   document.getElementsByTagName('a')[1].style.color = "#004B36";
		   document.getElementsByTagName('a')[2].style.color = "#004B36";
		   document.getElementsByTagName('h1')[0].style.background = "#A6CD5A";
		   document.getElementsByTagName('h1')[0].style.color = "#004B36";
		   document.getElementsByTagName('h1')[0].style.padding = "20px";
		   document.body.style.overflow = "scroll";
		}

		//var cookieString = myWidth + "x" + myHeight;
		//this.setCookie("windowSize",cookieString,9000);
	}

/*
	Setting.prototype.getCookie = function(name) {
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
			return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	}

	Setting.prototype.setCookie = function( name, value, expires, path, domain, secure ) {
		var today = new Date();
		today.setTime( today.getTime() );
		if ( expires ) {
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		document.cookie = name+"="+escape( value ) +
			( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
			( ( path ) ? ";path=" + path : "" ) +
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
	}

	Setting.prototype.deleteCookie = function( name, path, domain ) {
		if ( getCookie( name ) ) document.cookie = name + "=" +
				( ( path ) ? ";path=" + path : "") +
				( ( domain ) ? ";domain=" + domain : "" ) +
				";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
*/
	return {
		Setting : Setting
	}

})();