/* World Enegy Functions */

try { document.execCommand("BackgroundImageCache", false, true); } catch(e) {}

var varglobal = new Object();
var kcOpen = false;
var kcTimeout = null;
var loginTimeout = null;
var loginOpen = false;
var loaded = false;


function openMainMenu(menuId,parentElem) {
	
	// if the main menu element exist
	if ($('main' + menuId + 'nav')) {
		
			if ($(parentElem)) {
				var thisPosition = Position.cumulativeOffset($(parentElem));
				
				$('main' + menuId + 'nav').style.left = thisPosition[0] + 'px';
				$('main' + menuId + 'nav').style.top = thisPosition[1] + 38 + 'px';
			}//end if			
			//alert($('main' + menuId + 'nav').style.left);
			
			//$('main' + menuId + 'nav').style.display='block';
		// Clear the menu timeout
		if (varglobal["menuTimeout" + menuId]) {
			clearTimeout(varglobal["menuTimeout" + menuId]);
		} //end if

			// Cancel the current effect and reset the opacity
			if (varglobal["menuEffect" + menuId]) {
				varglobal["menuEffect" + menuId].cancel();
				$('main' + menuId + 'nav').style.opacity='1';
				$('main' + menuId + 'nav').style.filter='alpha(opacity=100)';
				$('menuButton' + menuId).className = 'bluebuttonon';
			} //end if
	

			// if the menu is hidden, show it
			if ($('main' + menuId + 'nav').style.display == 'none') {

				// capture the menus original status
				//if (!varglobal["menuState" + menuId]) {
				//	varglobal["menuState" + menuId] = $('subnav' + menuId).className;
				//} //end if

				//$('subnav' + menuId).className = 'subnavon';
				$('menuButton' + menuId).className = 'bluebuttonon';

				$('main' + menuId + 'nav').style.opacity='0';
				$('main' + menuId + 'nav').style.filter='alpha(opacity=0)';
				$('main' + menuId + 'nav').style.display='block';

				//if (menuOpen == true) { 
					new Effect.Opacity('main' + menuId + 'nav', {duration:0.3, from:0.0, to:1.0});
				//} else {
				//	$('subnavContainer_' + menuId).style.width = 1 + 'px';
				//	new Effect.Morph('subnavContainer_' + menuId, { style:'width:220px;', duration:0.2 });
				//} //end if-else

				
			} //end if
		//} //end if
	} //end if
} //end function

function closeMainMenu(menuId) {
	thisMenu = menuId;
	
	if ($('main' + thisMenu + 'nav')) {
		var menu = thisMenu;
		timeout = "setTimeout(\"varglobal['menuEffect' + " + menu + "] = new Effect.Opacity('main' + " + menu + " + 'nav', {duration:0.3, from:1.0, to:0.0, afterFinish:function() {$('main' + " + menu + " + 'nav').style.display='none'; $('menuButton' + " + menu + ").className = 'bluebutton';}});\",50)";
		varglobal['menuTimeout' + menu] = eval(timeout);
	} //end if
} //end function



function openMainMenu2(menuId) {
	
	// if the main menu element exist
	if ($('flyout' + menuId)) {
		
		/*	if ($(parentElem)) {
				var thisPosition = Position.page($(parentElem));
				
				$('main' + menuId + 'nav').style.left = thisPosition[0] + 'px';
				$('main' + menuId + 'nav').style.top = thisPosition[1] + 38 + 'px';
			}//end if			
			//alert($('main' + menuId + 'nav').style.left);
		*/	
			//$('main' + menuId + 'nav').style.display='block';
			
			
			
		// Clear the menu timeout
		if (varglobal["menuTimeout" + menuId]) {
			clearTimeout(varglobal["menuTimeout" + menuId]);
		} //end if

			// Cancel the current effect and reset the opacity
			if (varglobal["menuEffect" + menuId]) {
				varglobal["menuEffect" + menuId].cancel();
				$('flyout' + menuId).style.opacity='1';
				$('flyout' + menuId).style.filter='alpha(opacity=100)';
				$('flyoutMain' + menuId).parentNode.className = $('flyoutMain' + menuId).getAttribute('name') + 'on';
				//$('menuButton' + menuId).className = 'bluebuttonon';
			} //end if
	

			// if the menu is hidden, show it
			if ($('flyout' + menuId).style.display == 'none') {
				
				
				if ($('flyoutMain' + menuId)) {
					var thisPosition = Position.cumulativeOffset($('flyoutMain' + menuId));
				
					$('flyout' + menuId).style.left = thisPosition[0] + 120 + 'px';
					$('flyout' + menuId).style.top = thisPosition[1] + 'px';
					
					$('flyoutMain' + menuId).parentNode.className = $('flyoutMain' + menuId).getAttribute('name') + 'on';
					
				}//end if			
				

				//$('subnav' + menuId).className = 'subnavon';
				//$('menuButton' + menuId).className = 'bluebuttonon';
				
				if ($('flyout' + menuId).style.height == '') {
					//alert($('flyout' + menuId).getHeight());
					$('flyout' + menuId).style.height = $('flyout' + menuId).getHeight() + 'px';
					$('flyout' + menuId + '_bg').style.height = $('flyout' + menuId).getHeight() + 'px';
					$('flyout' + menuId + '_content').style.height = $('flyout' + menuId).getHeight() + 'px';
					$('flyout' + menuId + '_content').style.opacity='1';
					$('flyout' + menuId + '_content').style.filter='alpha(opacity=100)';
					$('flyout' + menuId + '_bg').style.opacity='0.9';
					$('flyout' + menuId + '_bg').style.filter='alpha(opacity=90)';
				} //end if
				
				
				
				$('flyout' + menuId).style.opacity='0';
				$('flyout' + menuId).style.filter='alpha(opacity=0)';
				$('flyout' + menuId).style.display='block';

				//if (menuOpen == true) { 
					new Effect.Opacity('flyout' + menuId, {duration:0.3, from:0.0, to:1.0});
				//} else {
				//	$('subnavContainer_' + menuId).style.width = 1 + 'px';
				//	new Effect.Morph('subnavContainer_' + menuId, { style:'width:220px;', duration:0.2 });
				//} //end if-else

				
			} //end if
		//} //end if
	} //end if
} //end function

function closeMainMenu2(menuId) {
	thisMenu = menuId;
	
	if ($('flyout' + thisMenu)) {
		var menu = thisMenu;
		timeout = "setTimeout(\"varglobal['menuEffect' + " + menu + "] = new Effect.Opacity('flyout' + " + menu + ", {duration:0.3, from:1.0, to:0.0, afterFinish:function() {$('flyout' + " + menu + ").style.display='none'; $('flyoutMain' +  + " + menu + ").parentNode.className = $('flyoutMain' +  + " + menu + ").getAttribute('name');}});\",50)";
		varglobal['menuTimeout' + menu] = eval(timeout);
	} //end if
} //end function








function openMenu(menuId,parentId) {
	

	// if the main menu element exist
	if ($('main' + parentId + 'nav')) {

		// if the sub menu container exists
		if ($('subnavContainer_' + menuId) && $('subnavBox_' + menuId)) {

			// Clear the menu timeout
			try {
				if (varglobal["menuTimeout" + menuId]) {
					clearTimeout(varglobal["menuTimeout" + menuId]);
				} //end if
			} catch(e) {}
			
			// Cancel the current effect and reset the opacity
			try {
				if (varglobal["menuEffect" + menuId]) {
					try { varglobal["menuEffect" + menuId].cancel(); } catch(e) {  }
					$('subnavContainer_' + menuId).style.opacity='1';
					$('subnavContainer_' + menuId).style.filter='alpha(opacity=100)';
					$('subnav' + menuId).className = 'subnavon';
				} //end if
			} catch(e) {}
			
			// Initialize mainNav and get its global position
			var mainNav = $('main' + parentId + 'nav');
			var thisPosition = Position.cumulativeOffset(mainNav); 
			
			// Calculate the height of the main menu
			var thisHeight = mainNav.getHeight();
	
			// if the menu is hidden, show it
			if ($('subnavContainer_' + menuId).style.display == 'none') {

				// capture the menus original status
				try {
					if (!varglobal["menuState" + menuId]) {
						varglobal["menuState" + menuId] = $('subnav' + menuId).className;
					} //end if
				} catch(e) {}


				$('subnav' + menuId).className = 'subnavon';
				
				$('subnavBox_' + menuId).style.overflow = 'hidden';
				$('subnavBox_' + menuId).style.height = (thisHeight-8) + 'px';
				$('subnavContainer_' + menuId).style.top = (thisPosition[1]) + 'px';
				$('subnavContainer_' + menuId).style.left = (thisPosition[0]+197) + 'px';
				$('subnavContainer_' + menuId).style.opacity='0';
				$('subnavContainer_' + menuId).style.filter='alpha(opacity=0)';
				$('subnavContainer_' + menuId).style.display='block';
				//if (menuOpen == true) { 
					
					try { new Effect.Opacity('subnavContainer_' + menuId, {duration:0.3, from:0.0, to:1.0}); } catch(e) {  }

				//} else {
				//	$('subnavContainer_' + menuId).style.width = 1 + 'px';
				//	new Effect.Morph('subnavContainer_' + menuId, { style:'width:220px;', duration:0.2 });
				//} //end if-else

				
			} //end if
		} //end if
	} //end if
} //end function

function closeMenu(menuId) {
	thisMenu = menuId;
	
	if ($('subnavContainer_' + thisMenu)) {
		var menu = thisMenu;
		//if ($(varglobal)) {
			timeout = "setTimeout(\"try {  if (loaded == true) { varglobal['menuEffect' + " + menu + "] = new Effect.Opacity('subnavContainer_" + menu + "', {duration:0.3, from:1.0, to:0.0, afterFinish:function() {$('subnavContainer_' + " + menu + ").style.display='none';}}); if (varglobal['menuState' + " + menu + "]) { $('subnav' + " + menu + ").className = varglobal['menuState' + " + menu + "]; } else { $('subnav' + " + menu + ").className = 'subnav';} } } catch(e) {}\",50)";
			//timeout = "setTimeout(\"try {  if (loaded == true) { $('subnavContainer_' + " + menu + ").style.display='none'; if (varglobal['menuState' + " + menu + "]) { $('subnav' + " + menu + ").className = varglobal['menuState' + " + menu + "]; } else { $('subnav' + " + menu + ").className = 'subnav';} } } catch(e) {}\",50)";
			try { varglobal['menuTimeout' + menu] = eval(timeout); } catch(e) {};
		//} //end if
	} //end if
} //end function





function openKnowledgeCenter(loc,state) {

	// if knowledgeCenter element exists
	if ($('knowledgeCenter') && $('knowledgeCenterMenu')) {
		
		if (kcOpen == true) {
			clearTimeout(kcTimeout);
		} //end if

		if (state == 'open') {
		
			var thisPosition = Position.cumulativeOffset($('knowledgeCenter'));
			var thisWidth = $('knowledgeCenter').getWidth();
			//var thisRight = screenSize('width')-(thisPosition[0]+thisWidth);
			
			$('knowledgeCenterMenu').style.width = thisWidth-2 + 'px';
			$('knowledgeCenterMenu').style.top = thisPosition[1] + 'px';
			$('knowledgeCenterMenu').style.left = thisPosition[0] + 'px';
			
			$('knowledgeCenterMenu').style.display='block';
			//$('knowledgeCenter').style.display='none';
			
			//var thisLeft = thisPosition[0];
			
			if (loc == 'home') {
				var thisTop = thisPosition[1] - 86;
				new Effect.Morph('knowledgeCenterMenu', { style:'width:286px;height:219px;top:' + thisTop + 'px;', duration:0.2, afterFinish:function() { kcOpen = true; } });
			} else {
				var thisLeft = thisPosition[0] - (288 - thisWidth);
				new Effect.Morph('knowledgeCenterMenu', { style:'width:286px;height:219px;left:' + thisLeft + 'px;', duration:0.2, afterFinish:function() { kcOpen = true; } });
			} //end if-else
		} //end if
	} //end if

} //end function


function closeKnowledgeCenter(loc) {

	// if knowledgeCenter element exists
	if ($('knowledgeCenter') && $('knowledgeCenterMenu')) {

		if (kcOpen == true) {
			
			kcPosition = Position.cumulativeOffset($('knowledgeCenter'));
			kcWidth = $('knowledgeCenter').getWidth()-2;

			if (loc == 'home') {
				kcTimeout = setTimeout("new Effect.Morph('knowledgeCenterMenu', { style:'top:' + kcPosition[1] + 'px;height:32px;', duration:0.2, afterFinish:function() { kcOpen = false;$('knowledgeCenterMenu').style.display='none'; } });",200);
			} else {
				kcTimeout = setTimeout("new Effect.Morph('knowledgeCenterMenu', { style:'width:' + kcWidth + 'px;height:32px;left:' + kcPosition[0] + 'px;', duration:0.2, afterFinish:function() { kcOpen = false;$('knowledgeCenterMenu').style.display='none'; } });",200);
			} //end if-else
		} //end if
		//$('knowledgeCenterMenu').style.height='32px';
		//$('knowledgeCenterMenu').style.display='none';
	} //end if

} //end function



function kcRollImg(img) {
	if (img) {
		$('kcRollImage').src = img;		
	} else {
		$('kcRollImage').src = 'http://66.205.71.108/images/spacer.gif';
	} //end if-else
} //end function


function loginOn(state) {
	
	// Clear the login timeout
	if (loginOpen == true) {
		clearTimeout(loginTimeout);
	} //end if
			
	if (state == 'open') {
		
		var thisPosition = Position.cumulativeOffset($('login'));
	
		$('loginDropDown').style.top=thisPosition[1] + 'px';
		$('loginDropDown').style.left=thisPosition[0] + 'px';
		$('loginDropDown').style.opacity='0';
		$('loginDropDown').style.filter='alpha(opacity=0)';
		$('loginDropDown').style.display='block';
		new Effect.Opacity('loginDropDown', {duration:0.3, from:0.0, to:1.0, afterFinish:function() { loginOpen = true; }});
		//new Effect.Morph('loginDropDown', {duration:0.3, style:'height:400px;', afterFinish:function() { loginOpen = true; }});
	} //end if

} //end function


function loginOff() {
	
	if (loginOpen == true) {
		loginTimeout = setTimeout("new Effect.Opacity('loginDropDown', {duration:0.3, from:1.0, to:0.0, afterFinish:function() {$('loginDropDown').style.display='none';loginOpen = false;}});",100);
	} //end if
		//$('loginDropDown').style.display='none';
} //end function



/* Utility Functions */


function resizeWin() {
	loaded = true;
	//new Insertion.Bottom('wrapper', "<span id='testx'>test</span>");
	
	$('wrapper').style.height = '100%';
	if ($('wrapper').getHeight() <  screenSize('height')) {
		$('wrapper').style.height = screenSize('height') + 'px';
	} //end if

	if ($('footer')) {
		$('footer').style.position = '';
		$('footer').style.top = '';
	
		if (Position.cumulativeOffset($('footer'))[1] < screenSize('height')) {
			$('footer').style.position = 'absolute';
			$('footer').style.top = screenSize('height') - 20 + 'px';
		} //end if
	} //end if

	if ($('flashcontent') && $('hoverNav')) {
		var thisPosition = Position.cumulativeOffset($('flashcontent'));
		var thisHeight = $('hoverNav').getHeight();
		
		$('hoverNav').style.display = 'block';
		$('hoverNav').style.top = thisPosition[1] + (252 - thisHeight) + 'px';
		$('hoverNav').style.left = thisPosition[0] + 'px';
	} //end if

} //end function

function screenSize(axis) {

	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else {
		if( document.documentElement &&
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  //IE 6+ in 'standards compliant mode'
		  myWidth = document.documentElement.clientWidth;
		  myHeight = document.documentElement.clientHeight;
		} else {
		  if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		}
	  }

	if (axis == 'width') {
		return myWidth;
	} else {
		return myHeight;
	} // end if
} //end function

function openDemo(path,width,height) {
	window.open(path, 'demo', 'width=' + width + ',height=' + height + ',scrollbars=no,resize=no');
} //end 


//for (x in window.scrollbars) {
//alert(x + ' ' + window.scrollbars[x]);
//}