var currentMenu = null;
var lastMenu = null;
var lastNum = null;
var abortCode = null;

var menuoff = new Array(5);
var menuon = new Array(5);

function init() {
	if (document.getElementById) {
		document.getElementById("menu0").onmouseover = function(e) { switchTo(document.getElementById("menu0"), 0); };
		document.getElementById("menu0").onmouseout = function(e) { switchOff(document.getElementById("menu0"), 0); };
		document.getElementById("menu1").onmouseover = function(e) { switchTo(document.getElementById("menu1"), 1); };
		document.getElementById("menu1").onmouseout = function(e) { switchOff(document.getElementById("menu1"), 1); };
		document.getElementById("menu2").onmouseover = function(e) { switchTo(document.getElementById("menu2"), 2); };
		document.getElementById("menu2").onmouseout = function(e) { switchOff(document.getElementById("menu2"), 2); };
		document.getElementById("menu3").onmouseover = function(e) { switchTo(document.getElementById("menu3"), 3); };
		document.getElementById("menu3").onmouseout = function(e) { switchOff(document.getElementById("menu3"), 3); };
		document.getElementById("menu4").onmouseover = function(e) { switchTo(document.getElementById("menu4"), 4); };
		document.getElementById("menu4").onmouseout = function(e) { switchOff(document.getElementById("menu4"), 4); };
		document.getElementById("menu5").onmouseover = function(e) { switchTo(document.getElementById("menu5"), 5); };
		document.getElementById("menu5").onmouseout = function(e) { switchOff(document.getElementById("menu5"), 5); };
		
		var i=0;
		while(i<=5) {
			menuoff[i] = new Image();
			menuon[i] = new Image();
	    	menuoff[i].src=document.getElementById("menuimg"+i).src;
	    	if(i<6)	menuon[i].src=menuoff[i].src.replace(/off/,"on");
	    	else menuon[i].src=menuoff[i].src;
	    	i++;
    	}
		
		defaultOn();
		
		//Fix stupid NS6 bug
		if(is.ns6 && (shortName == "staff")) {
			if(document.getElementById("contentTable")) {
				document.getElementById("contentTable").getElementsByTagName("td").item(0).width="76%";
			}
		}
		
	}
}

function onloadinit() {
	if (document.getElementById) {
		if(shortName && shortName=="home") {
			addRollover("imgbox1", "/img/home/therapybox_home_on.gif");
			addRollover("imgbox2", "/img/home/fitnessbox_home_on.gif");
			addRollover("imgbox3", "/img/home/wellnessbox_home_on.gif");
		}
	}
}


addRolloverPre = new Array();
function addRollover(id, onsrc) {
	var img = document.getElementById(id);
	img.offsrc = img.src;
	img.onsrc = onsrc;
	addRolloverPre[id] = new Image;
	addRolloverPre[id].src = onsrc;
	img.onmouseover = function(){this.src=this.onsrc;}
	img.onmouseout = function(){this.src=this.offsrc;}
}

function switchTo(what, num) {
	if(abortCode) clearTimeout(abortCode);

	if(num != lastNum) {
		if(lastNum>=0) {
			document.getElementById("menuimg" + lastNum).src = menuoff[lastNum].src;
			lastMenu.className = "";
		}
		document.getElementById("menuimg" + num).src = menuon[num].src;
		what.className = "active";

		lastMenu=what;
		lastNum=num;
	}

}

function switchOff(what, num) {
	if(abortCode) clearTimeout(abortCode);
	
	if(num==5) abortCode = setTimeout('restoreDefault()', 60);
	else abortCode = setTimeout('restoreDefault()', 1500);
}	

function restoreDefault() {
	if(lastNum != thisMenu) {
		if(lastNum>=0) {
			document.getElementById("menuimg" + lastNum).src = menuoff[lastNum].src;
			lastMenu.className = "";
		}
		defaultOn();
	}
}

function defaultOn() {
		if(thisMenu>=0) {
			document.getElementById("menu" + thisMenu).className = "active";
			document.getElementById("menuimg" + thisMenu).src = menuon[thisMenu].src;

			lastMenu=document.getElementById("menu" + thisMenu);
		}
		lastNum=thisMenu;
}
	
function noSpam(user, domain) {
	locationstring = "mailto:" + user + "@" + domain;
    window.location = locationstring;
}

var pageShrink=false;

function floatLayers() {
	if(pageShrink) {
		pageShrink=false;
		logoLayer.moveTo(null, 300);
		menuLayer.moveTo(null, 100);
	}
	else {
		var window_height=is.ie? document.body.clientHeight : window.innerHeight
		if(ie6) { window_height=document.documentElement.clientHeight }
		pageY=is.ie?document.body.scrollTop:window.pageYOffset
		if(ie6) { pageY=document.documentElement.scrollTop }
		
		var window_width=is.ie? document.body.clientWidth : window.innerWidth
		if(ie6) { window_width=document.documentElement.clientWidth }
		pageX=is.ie?document.body.scrollLeft:window.pageXOffset
		if(ie6) { pageX=document.documentElement.scrollLeft }

		var newX = 0;
		if(window_width < menuMinWidth) newX = menuMinWidth-menuBaseX;
		else newX = window_width - menuBaseX - (menuPercentX*(window_width-menuMinWidth))/100;
		
		logoLayer.moveBy(null,((window_height+pageY-logoY)-logoLayer.y)/12)
		menuLayer.moveBy((newX-menuLayer.x)/5,((pageY < (menuStartY-menuSquishY) ? menuStartY : pageY+menuSquishY)-menuLayer.y)/5)
	}
	setTimeout('floatLayers()',20)
}

function addEvents(items) {
	if (document.getElementById) {
		var i=0;
		while(i<items) {
			document.getElementById("sideitem"+i).onmouseover = new Function ("", "sideActive("+i+");");
			document.getElementById("sideitem"+i).onmouseout = new Function ("", "sideInactive("+i+");");
			i++;
		}
		document.getElementById("sideitembtt").onmouseover = new Function ("", "sideActive(\"btt\");");
		document.getElementById("sideitembtt").onmouseout = new Function ("", "sideInactive(\"btt\");");
	}
}

function windowSize() {
	var window_height=is.ie? document.body.clientHeight : window.innerHeight
	if(ie6) { window_height=document.documentElement.clientHeight }
	
	var window_width=is.ie? document.body.clientWidth : window.innerWidth
	if(ie6) { window_width=document.documentElement.clientWidth }

	alert("Page size is "+window_width+"x"+window_height+".");
		
}

function sideActive(num) {
	document.getElementById("sideitem"+num).className="sideon";
}

function sideInactive(num) {
	document.getElementById("sideitem"+num).className="sideoff";
}

//Function moves this code out of HTML file to prevent w3c validation error
function initLayers(menuHTML) {
	logoLayer.setHTML('<div id="logoHider"><a href="'+rootPath+'"><img class="logo" src="'+rootPath+'img/logo.gif" alt="Back To Mettler Home"></a></div>')
	//menuLayer.setHTML('<table class="sidemenu"><tr><td class="sidemain"><img src="'+rootPath+'img/menu/rightsubnav-top.gif" alt=""></td></tr>'+menuHTML+'<tr class="sidemain"><td><img src="'+rootPath+'img/menu/rightsubnav-bottom.gif" alt=""></td></tr></table>')
	menuLayer.setHTML('<div id="sidemenu"><div id="sidemenutop"><img src="'+rootPath+'img/menu/rightsubnav-top.gif" alt=""></div>'+menuHTML+'<div id="sideitemspc">&nbsp;</div><div id="sideitembtt" class="sideoff"><a href="#top">Back To Top</a></div><div id="sidemenubottom"><img src="'+rootPath+'img/menu/rightsubnav-bottom.gif" alt=""></div></div>')
}

function onSubNav(level, menu, row) {
	if(level==0) {
		DynAPI.document.all["menuMid"+menu+"-"+row].setBgColor('#'+thisStyleNAV1);
		document.getElementById("mImgMid"+menu+"-"+row).src=rootPath+'img/menu/subnavarrow-white.gif';
	}
	else { //level==1
		DynAPI.document.all["menuLow"+menu+"-"+row].setBgColor('#'+thisStyleNAV2);
		//DynAPI.document.all["menuLow"+menu+"-"+row].setBgColor('#'+thisStyleNAV1);
		document.getElementById("mImgLow"+menu+"-"+row).src=rootPath+'img/menu/subnavarrow-black.gif';
	}
	
	if(menu==thisMenu) {
		if((level==thisLevel)&&(row==thisRow)) {
		}
		else {
			offDefSubNav();
		}
	}
}

//DynAPI.document.all[\"menuMid<?php echo $i;?>-\"+"+j+"].setBgColor('#<?php echo $colors[$thisStyle][$C_MENU];?>'); document.getElementById(\"mImgMid<?php echo $i;?>-\"+"+j+").src='<?php echo $rootPath;?>img/spacer.gif';	
function offSubNav(level, menu, row) {
	if(level==0) {
		DynAPI.document.all["menuMid"+menu+"-"+row].setBgColor('#'+thisStyleMENU);
		document.getElementById("mImgMid"+menu+"-"+row).src=rootPath+'img/spacer.gif';	
	}
	else { //level==1
		//DynAPI.document.all["menuLow"+menu+"-"+row].setBgColor('#'+thisStyleMENU);
		DynAPI.document.all["menuLow"+menu+"-"+row].setBgColor('#DADDE1');
		document.getElementById("mImgLow"+menu+"-"+row).src=rootPath+'img/spacer.gif';	
	}
	
	onDefSubNav();
}

firstODSN=true;
abortODSN=-1;

function onDefSubNav() {
	if(thisLevel<0) return;
	if(firstODSN) {
		firstODSN=false;
		reallyODSN();
	}
	else {
		abortODSN = setTimeout('reallyODSN()', 350);
	}
}

function reallyODSN() {
	if(thisLevel==0) {
		DynAPI.document.all["menuMid"+thisMenu+"-"+thisRow].setBgColor('#'+thisStyleNAV1);
		document.getElementById("mImgMid"+thisMenu+"-"+thisRow).src=rootPath+'img/menu/subnavarrow-white.gif';
	}
	else { //level==1
		DynAPI.document.all["menuLow"+thisMenu+"-"+thisRow].setBgColor('#'+thisStyleNAV2);
		//DynAPI.document.all["menuLow"+thisMenu+"-"+thisRow].setBgColor('#'+thisStyleNAV1);
		document.getElementById("mImgLow"+thisMenu+"-"+thisRow).src=rootPath+'img/menu/subnavarrow-black.gif';
	}
}

function offDefSubNav() {
	if(thisLevel<0) return;
	if(abortODSN) clearTimeout(abortODSN);
	
	if(thisLevel==0) {
		DynAPI.document.all["menuMid"+thisMenu+"-"+thisRow].setBgColor('#'+thisStyleMENU);
		document.getElementById("mImgMid"+thisMenu+"-"+thisRow).src=rootPath+'img/spacer.gif';	
	}
	else { //level==1
		DynAPI.document.all["menuLow"+thisMenu+"-"+thisRow].setBgColor('#DADDE1');
		//DynAPI.document.all["menuLow"+thisMenu+"-"+thisRow].setBgColor('#'+thisStyleMENU);
		document.getElementById("mImgLow"+thisMenu+"-"+thisRow).src=rootPath+'img/spacer.gif';	
	}
}

// Original JavaScript code by Duncan Crombie: dcrombie at chirp.com.au
// Please acknowledge use of this code by including this header.

var bites = document.cookie.split("; "); // break cookie into array of bites

function getCookie(name) { // use: getCookie("name");
	for (var i=0; i < bites.length; i++) {
		nextbite = bites[i].split("="); // break into name and value
		if (nextbite[0] == name) // if name matches
	    	return unescape(nextbite[1]); // return value
	}
	return null;
}

var today = new Date();
var expiry = new Date(today.getTime() + 1000 * 24 * 60 * 60 * 1000); // plus 1000 days

function setCookie(name, value) { // use: setCookie("name", value);
	if (value != null && value != "")
		document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/;";
	bites = document.cookie.split("; "); // update cookie bites
}

myFontSize = 0.8;

function setupTextSizer() {
	largeroff = new Image();
	largeron = new Image();
	largeroff.src = "/img/resize/larger-off.gif";
	largeron.src = "/img/resize/larger-on.gif";

	smalleroff = new Image();
	smalleron = new Image();
	smalleroff.src = "/img/resize/smaller-off.gif";
	smalleron.src = "/img/resize/smaller-on.gif";

	document.getElementById("makelarger").onmouseover = function(e) { document.getElementById("makelarger").src = largeron.src; };
	document.getElementById("makelarger").onmouseout = function(e) { document.getElementById("makelarger").src = largeroff.src; };
	document.getElementById("makesmaller").onmouseover = function(e) { document.getElementById("makesmaller").src = smalleron.src; };
	document.getElementById("makesmaller").onmouseout = function(e) { document.getElementById("makesmaller").src = smalleroff.src; };
	
	bites = document.cookie.split("; "); // update cookie bites
	cookieSize = getCookie("myFontSize");
	if(cookieSize && (cookieSize > 0.3) && (cookieSize < 2.1)) {
		myFontSize = getCookie("myFontSize");
		myFontSize=(Math.round(10*myFontSize))/10;
	}
	document.body.style.fontSize = myFontSize+"em";
}

function makelarger() {
	if(myFontSize < 1.9) {
		myFontSize=0+myFontSize+0.1;
		myFontSize=(Math.round(10*myFontSize))/10;
		document.body.style.fontSize = myFontSize+"em";
		setCookie("myFontSize", myFontSize);
		parent.scroll(0, 60000); //Scroll to page bottom
	}
}

function makesmaller() {
	if(myFontSize > 0.5) {
		myFontSize=0+myFontSize-0.1;
		myFontSize=(Math.round(10*myFontSize))/10;
		document.body.style.fontSize = myFontSize+"em";
		setCookie("myFontSize", myFontSize);
		pageShrink=true;
	}
}

