/* Power strip monitor and background image control.  Written by Joe McCormack.  Copyright 2005.  All Rights Reserved.  www.gamephasma.com */
var power_flag = 1;
var background_sel = 1;
var background_max = 12;
var shell_visible = ""; nav_visible=""; main_visible=""; menu_shell_visible = ""; menu_nav_visible=""; menu_main_visible=""; back_was=""; main_source="";
var avails = new Array();
avails[1] = "/Img/background_1.jpg";
avails[2] = "/Img/background_3.jpg";
avails[3] = "/Img/background_2.jpg";
avails[4] = "/Img/background_4.jpg";
avails[5] = "/Img/background_5.jpg";
avails[6] = "/Img/background_6.jpg";
avails[7] = "/Img/background_7.jpg";
avails[8] = "/Img/background_8.jpg";
avails[9] = "/Img/background_9.jpg";
avails[10] = "/Img/background_10.jpg";
avails[11] = "/Img/background_11.jpg";
avails[12] = "/Img/background_12.jpg";

var medavails = new Array();
medavails[1] = "/Img/back_med_1.jpg";
medavails[2] = "/Img/back_med_3.jpg";
medavails[3] = "/Img/back_med_2.jpg";
medavails[4] = "/Img/back_med_4.jpg";
medavails[5] = "/Img/back_med_5.jpg";
medavails[6] = "/Img/back_med_6.jpg";
medavails[7] = "/Img/back_med_7.jpg";
medavails[8] = "/Img/back_med_8.jpg";
medavails[9] = "/Img/back_med_9.jpg";
medavails[10] = "/Img/back_med_10.jpg";
medavails[11] = "/Img/back_med_11.jpg";
medavails[12] = "/Img/back_med_12.jpg";

var largeavails = new Array();
largeavails[1] = "/Img/back_large_1.jpg";
largeavails[2] = "/Img/back_large_3.jpg";
largeavails[3] = "/Img/back_large_2.jpg";
largeavails[4] = "/Img/back_large_4.jpg";
largeavails[5] = "/Img/back_large_5.jpg";
largeavails[6] = "/Img/back_large_6.jpg";
largeavails[7] = "/Img/back_large_7.jpg";
largeavails[8] = "/Img/back_large_8.jpg";
largeavails[9] = "/Img/back_large_9.jpg";
largeavails[10] = "/Img/back_large_10.jpg";
largeavails[11] = "/Img/back_large_11.jpg";
largeavails[12] = "/Img/back_large_12.jpg";

function power_set(pagename,resolution) {
	
	//check to see what whether the monitor is in power save or not
	if (power_flag == 1) {
		//these check the visibility of the menu and store it later for when the monitor is turend back on
		//if the menu is on it is also turned off
		if (document.getElementById("Shell").style.visibility == "hidden"){
			shell_visible = "hidden";
			}
		else {
			shell_visible = "visible";
			}
		if (document.getElementById("TableContent").style.visibility == "hidden"){
			main_visible = "hidden";
			}
		else {
			main_visible = "visible";
			}
		if (document.getElementById("menuShell").style.visibility == "hidden"){
			menu_shell_visible = "hidden";
			}
		else {
			menu_shell_visible = "visible";
			}
		if (document.getElementById("menuMain").style.visibility == "hidden"){
			menu_main_visible = "hidden";
			}
		else {
			menu_main_visible = "visible";
			}
		
		//store the background for later reference
		back_was=document.getElementById("setme").src;				
		if (resolution=="highres"){
			document.getElementById("setme").src = "/Img/power_save_large.gif";
			}
		else if (resolution=="mediumres"){
			document.getElementById("setme").src = "/Img/power_save_med.gif";
			}
		else {					
			document.getElementById("setme").src = "/Img/power_save.gif";
			}
			
		//storing the source of the main content for later reference
		main_source = document.getElementById("MainContent").src;
		//set the flag that the monitor is off
		power_flag = 0;
		//set the power button image to reflect the off state
		document.getElementById("power_monitor").src = "/Img/PowerButtons_Off.gif";
		//the source of the iframe needs to be set to nothing because scrollbars will still display on firefox and safari
		document.getElementById("MainContent").src = "";
		document.getElementById("w_test_frame").src = "";
		
		//hiding all the elements
		document.getElementById("overlay_icons").style.visibility = "hidden";
		document.getElementById("MainContent").style.visibility = "hidden";
		document.getElementById("menuRequest").style.visibility = "hidden";
		document.getElementById("menuApply").style.visibility = "hidden";
		document.getElementById("menuShell").style.visibility = "hidden";
		document.getElementById("menuMain").style.visibility = "hidden";
		
		//these items tend to not be visible and do not return when the monitor is turned back on
		document.getElementById("promobox").style.visibility = "hidden";
		document.getElementById("promospot").style.visibility = "hidden";
		document.getElementById("arcadebox").style.visibility = "hidden";
		document.getElementById("w_test").style.visibility = "hidden";
		
		//these all hide the draggable windows
		wcontrolarr_set("Shell","hidden",1);
		wcontrolarr_set("TableContent","hidden",1);
		wcontrolarr_set("w_test","hidden",1);
		
		//this hides the pop up window and sets it to nothing
		PopUp("none");
		
		//popupTest is located on the default.asp page and controls whether the nav window there is displayed or not
		if (pagename != "default" || popupTest==1){					
			if (document.getElementById("SubNavWindow").style.visibility == "hidden"){
				nav_visible = "hidden";
				}
				else {nav_visible = "visible";
				}
			if (document.getElementById("menuNav").style.visibility == "hidden"){
				menu_nav_visible = "hidden";
				}
				else {menu_nav_visible = "visible";
				}
			wcontrolarr_set("SubNavWindow","hidden",1);
			document.getElementById("menuNav").style.visibility = "hidden";
			document.getElementById("subNav").style.visibility = "hidden";
		}
		//this is located in minimize.js and sets whether the pop up will come up correctly when power is turned back on
		minTest=1;
	}
	else {
		//set the flag that the power is on
		power_flag = 1;
		//set background image back to it's original state, check to see if the res size was changed during power off first
		back_was = PowerBack(back_was,resolution);
		//set the power button to the 'on' state
		document.getElementById("power_monitor").src = "/Img/PowerButtons_On.gif";
		//turn on the draggable windows
		wcontrolarr_set("Shell",shell_visible,1);
		wcontrolarr_set("TableContent",main_visible,1);
		//turn elements back on
		document.getElementById("overlay_icons").style.visibility = "visible";
		document.getElementById("menuRequest").style.visibility = "visible";
		document.getElementById("menuApply").style.visibility = "visible";
		//elements set back to their states before monitor turned off
		document.getElementById("Shell").style.visibility = shell_visible;
		document.getElementById("MainContent").style.visibility = main_visible;
		document.getElementById("menuShell").style.visibility = menu_shell_visible;
		document.getElementById("menuMain").style.visibility = menu_main_visible;
		
		//restore the sources of the iframes
		document.getElementById("MainContent").src = main_source;
		document.getElementById("setme").src = back_was;
		//popupTest is located on the default.asp page and controls whether the nav window is being displayed there or not
		//check to see if it's the default page or subnav is enabled on default page
		if (pagename != "default" || popupTest==1){	
			document.getElementById("SubNavWindow").style.visibility = nav_visible;
			document.getElementById("menuNav").style.visibility = nav_visible;
			document.getElementById("subNav").style.visibility = nav_visible;
			wcontrolarr_set("SubNavWindow",nav_visible,1);
		}
	}
}

function bgchanger(direction) {
if (power_flag == 1) {
	if (direction > 0) { 
		background_sel = background_sel + 1; 
	} 	
	else { 
		background_sel = background_sel - 1; 
	}
	if (background_sel > background_max) { 
		background_sel = 1; 
	}
	if (background_sel < 1) { 
		background_sel = background_max; 
	}
	
	//the array that the image is chosen from is determined by how wide the image is
	if (document.getElementById("setme").width==813){	
		document.getElementById("setme").src = medavails[background_sel];
	}
	else if (document.getElementById("setme").width==990){	
		document.getElementById("setme").src = largeavails[background_sel];
	}
	else {
		document.getElementById("setme").src = avails[background_sel];}
	}
}

/*this takes in the ID of the image tag that you want to change and the name of the new image and splits the
	path name to the image into an array.  Then both are handed to the pathchange function in pathchange.js.*/
function PowerBack(name,res){
	var oldSource = name;
	//split the URL and store it in the array
	var sourceHolder = oldSource.split('/');
	var imageHolder = new Array();
	var newSource = "";
	
	if (res=="mediumres"){
		//loop through the URL holding array
		for (i=0; i<sourceHolder.length; i++){
			//find the image folder
			if (sourceHolder[i] == "Img"){
				//split the image at the underscore
				imageHolder = sourceHolder[i+1].split('_');
				//check to see if it was the small background
				if(imageHolder[0] == "background"){
					//set it to the medium size background
					newSource = "back_med_" + imageHolder[1];
				}
				else {
					//check to see if it was the large background
					if (imageHolder[1] == "large"){
					//set it to the medium size background
						newSource = "back_med_" + imageHolder[2];
					}
					//otherwise the background didn't change
					else {
						newSource = "nothing";
					}
				}
			}
		}
	}
	else if (res=="highres"){
		//loop through the URL holding array
		for (i=0; i<sourceHolder.length; i++){
			//find the image folder
			if (sourceHolder[i] == "Img"){
				//split the image at the underscore
				imageHolder = sourceHolder[i+1].split('_');
				//check to see if it was the small background
				if(imageHolder[0] == "background"){
					//set it to the large size background
					newSource = "back_large_" + imageHolder[1];
				}
				else {
					//check to see if it was the large background
					if (imageHolder[1] == "med"){
						//set it to the medium size background
						newSource = "back_large_" + imageHolder[2];
					}
					//otherwise the background didn't change
					else {
						newSource = "nothing";
					}
				}
			}
		}
	}
	else {
		//loop through the URL holding array
		for (i=0; i<sourceHolder.length; i++){
			//find the image folder
			if (sourceHolder[i] == "Img"){
				//split the image at the underscore
				imageHolder = sourceHolder[i+1].split('_');
				//check to see if it was the large or medium background
				if(imageHolder[0] == "back"){
					//set it to the small size background
					newSource = "background_" + imageHolder[2];
				}
				//otherwise the background didn't change
				else {
					newSource = "nothing";
				}
			}
		}
	}
		
	//return the old image if it didn't change, otherwise assign the new image
	if (newSource == "nothing"){
		return oldSource;
	}
	else {	
		return PathChange(sourceHolder,newSource,'Img');
	}
}

