window.status="Menu System Loading..."
var IE5up = document.getElementById&&document.all;
var NS6up = document.getElementById&&!document.all;
var NS4 = document.layers;
var IE4 = document.all&&!window.print;
var AllReady = "false"; //gets set to true once the page has loaded, keeps errors from occuring if the menus are called before they load
var w; //holds the value for the active menus width
var loc; //holds the value for the active menus left position
var nloc = 0 //holds the value for the new location of the active menu position
var nwidth; //the nWidth is used to keep the menus from going past the right edge of the page
var totalwidth//the total available width of the page
var hmenulayer = "";
var templayer = "";
var menulayer = "";
var hStart;
var sStart;
var hideall_flag = false; 
//reloads netscape 4.x browsers if they are resized
if(document.layers) { 
var xX = innerWidth;
var yY = innerHeight; 
	onresize= function(){ 
		if(xX!= innerWidth || yY!= innerHeight) history.go(0); 
	}
}

function countInstances(string, word) {
  		var substrings = string.split(word);
  		return substrings.length - 1;
}

// markwidth used when page is centered to keep menu items centered as well
function markwidth(){
	nloc=parseInt( (totalwidth-pagewidth)/2 )
	if(document.layers){
	nloc=nloc-8; //because netscape is stupid
	}
	for(i=0;i<items.length;i++){
		if(NS4){
			document.layers[items[i][2]].left=document.layers[items[i][2]].left+nloc;
		}
		if(IE4){
			document.all[items[i][2]].style.left=document.all[items[i][2]].style.left+nloc;
		}
		if(IE5up||NS6up){
			document.getElementById(items[i][2]).style.left=(parseInt(items[i][1]))+nloc;
		}
	}	
}

function HideAll(){
	if(hideall_flag == true){
		for(n=0;n<items.length;n++){
			for(i=1;i<items[n].length;i++){
						document.getElementById(items[n][2]).style.visibility="hidden";
			}
		}
		hideall_flag=false;
	}
	else{
		hStart = setTimeout("HideAll()",1500);
		hideall_flag=true;
	}
}

function ShowIndvMenu(mlayer){
	if(templayer!=""&&templayer!=menulayer){
	document.getElementById(templayer).style.visibility="hidden";
	}
	document.getElementById(mlayer).style.visibility="visible";
	templayer = mlayer;
}

function ShowMenu(mlayer){
	menulayer = mlayer;
	clearTimeout(hStart);
	hideall_flag=false;
	sStart = setTimeout("ShowMenu2()",750);
}

function HideMenu(){
	if (AllReady=="true"){
		/*if((countInstances(menulayer,hmenulayer)==1) && (hmenulayer != menulayer)){
			//alert(hmenulayer +" and "+ menulayer);
		}
		else{
			if(IE5up||NS6up){
				document.getElementById(hmenulayer).style.visibility="hidden";
			}
			else if(NS4){
				document.layers[hmenulayer].visibility="hidden";
			}
			else if(IE4){
				document.all[hmenulayer].style.visibility="hidden";
			}
		}*/
		
		for(n=0;n<items.length;n++){
			for(i=1;i<items[n].length;i++){
					//if((items[n][2]!=menulayer) || (countInstances(menulayer,items[n][2])!=1)){
					if(countInstances(menulayer,items[n][2])!=1){
						document.getElementById(items[n][2]).style.visibility="hidden";
						//alert(menulayer +" includes "+ items[n][2] +" = " +countInstances(menulayer,items[n][2]));
					}
			}
		}
	}
	else{
	}
}

function ShowMenu2(){
	//added for PAICR flash banner
	if (AllReady=="true"){
		//alert(hmenulayer + " <- layer 1 and layer 2 -> " + menulayer);
		if((hmenulayer!=menulayer) && (hmenulayer!="")){
			HideMenu();
		}

		for(n=0;n<items.length;n++){
			for(i=1;i<items[n].length;i++){
				if(items[n][2]==menulayer){
				loc=parseInt(items[n][1]);
				}
			}
		}
		
		// start settings to calculate and assign nWidth if needed
		if(NS4){
			w = parseInt(document.layers[menulayer].clip.width);
		}
		if(IE4){
			w = parseInt(document.all[menulayer].offsetWidth);
		}
		if(IE5up||NS6up){
			w = parseInt(document.getElementById(menulayer).offsetWidth);
		}
		if((w+loc+nloc)>pagewidth+nloc){
			nWidth=parseInt(((pagewidth+nloc)-(w)));
			if(NS4){
				document.layers[menulayer].left=nWidth;
			}
			if(IE4){
				document.all[menulayer].style.left=nWidth;
			}
			if(IE5up||NS6up){
				document.getElementById(menulayer).style.left=nWidth;
			}
		}
		// end settings to calculate and assign nWidth if needed
		
		if(IE5up||NS6up){
			document.getElementById(menulayer).style.visibility="visible";
		}
		else if(NS4){
			document.layers[menulayer].visibility="visible";
		}
		else if(IE4){
			document.all[menulayer].style.visibility="visible";
		}
	hmenulayer = menulayer;
	}
	else{
	}
}

function SetTrue(){
AllReady = "true"
window.status="Menu System Now Loaded"
ClearStatus();
	if(pagecenter==true){
		findwidth();
	}
}

function ClearStatus(){
setTimeout("window.status=''",2000);
}
window.onload=SetTrue;

