var currentMenu=null;
var browserType="ie4";
var menuArray=new Array("m30","m300");
var layerString="x,";

if (navigator.appName.indexOf('Netscape')>=0){
	if (parseInt(navigator.appVersion)<5){
		browserType="n4";
		}
	else{
		browserType="5";
		}
	}
	
function addLayer(thisLayerName){
	//adds layers to layer string (if not there already)
	if(layerString.indexOf(","+thisLayerName+",")<1){
		layerString+=(thisLayerName+",");
		}
	}


//find url root

function navClose(newLoc){
	top.nav.enableMenus=null;
	top.main.document.location=newLoc;
	}

function enterMenu(thisMenuButton,openSub){
	currentMenuButton=thisMenuButton;
	var menuString="l"+thisMenuButton.substr(0,(thisMenuButton.length-1));
	var totalLayers=(menuString.length-2);
	var openArray=new Array();
	for(looper=0;looper<totalLayers;looper++){
		thisLayer=menuString.substr(0,(looper+3));
		openArray[looper]=thisLayer;
		}
	if(openSub){
		openArray[openArray.length]="l"+thisMenuButton;
		}
	for(looper=0;looper<menuArray.length;looper++){
		var closeIt=true;
		closeLayer=menuArray[looper];
		for(oLooper=0;oLooper<openArray.length;oLooper++){
			if(closeLayer==openArray[oLooper]){
				closeIt=false;
				break;
				}
			}
		if(closeIt){
			hideMenu(closeLayer);
			}
		}
	for(oLooper=0;oLooper<openArray.length;oLooper++){
		showMenu(openArray[oLooper]);
		}
	var totalButtons=(thisMenuButton.length-2);
	var onArray=new Array();
	for(looper=0;looper<totalButtons;looper++){
		thisButton=thisMenuButton.substr(0,(looper+3));
		onArray[looper]=thisButton;
		}
	thisButton=thisMenuButton.substr(0,2)+"0";
	onArray[onArray.length]=thisButton;
	var currentSection=top.nav.setMenuBar();
	if(currentSection!=null){
		onArray[onArray.length]=currentSection;
		}
	for(looper=0;looper<lastOnArray.length;looper++){
		var offIt=true;
		offButton=lastOnArray[looper];
		for(oLooper=0;oLooper<onArray.length;oLooper++){
			if(offButton==onArray[oLooper]){
				offIt=false;
				break;
				}
			}
		if(offIt){
			var thisDirectory=offButton.substr(0,(offButton.length-1));
			var thisImage=offButton.substr((offButton.length-1),offButton.length);
			var buttonLayer="l"+thisDirectory;
			var imageFile= findImageClass(thisDirectory,thisImage);
			
			if((offButton.length==3)&&(offButton.charAt(2)=="0")){
				var iSRC="/images/navigation/menubar/"+thisDirectory+"/"+thisImage+".jpg";
				}
			else{
				var iSRC="/images/navigation/"+imageFile+"/"+thisImage+".gif";
				}

			switchMe(offButton,buttonLayer,iSRC);
			}
		}
	for(oLooper=0;oLooper<onArray.length;oLooper++){
		var onButton=onArray[oLooper];
		var thisDirectory=onButton.substr(0,(onButton.length-1));
		var thisImage=onButton.substr((onButton.length-1),onButton.length);
		var buttonLayer="l"+thisDirectory;
		var imageFile= findImageClass(thisDirectory,thisImage);

		if((onButton.length==3)&&(onButton.charAt(2)=="0")){
			var iSRC="/images/navigation/menubar/"+thisDirectory+"/"+thisImage+"b.jpg";
			}
		else{
			var iSRC="/images/navigation/"+imageFile+"/"+thisImage+"b.gif";
			}

		switchMe(onButton,buttonLayer,iSRC);
		}
	lastOnArray=null;
	lastOnArray=onArray;
	}

function exitMenu(menuObject){
	currentMenu=null;
	setTimeout("closeAll()",500);
	}

function cleanClose(){
	if(currentMenuButton==null){
		closeAll();
		top.nav.setMenuBar();
		}
	}

function closeAll(){
	//alert(currentMenu);
	menuArray=layerString.split(",");
	for(looper=0;looper<menuArray.length;looper++){
		if(menuArray[looper].length>1){
			if(currentMenu!=null){
				if(currentMenu.indexOf(menuArray[looper])<0){
					hideMenu(menuArray[looper]);
					}
			}else{
				hideMenu(menuArray[looper]);
				}
			}
		}
	}
	
function endMenu(menuObject){
	currentMenu="m"+menuObject.name.substr(1,menuObject.name.length-2);
}

function showMenu(menuObject){
	//thisMenu=eval("document."+menuObject.name+"0");
	currentMenu="m"+menuObject.name.substr(1,menuObject.name.length);
	thisMenu=currentMenu;
	if (browserType=="n4"){
		if(thisMenu=='main'){
			alert("that's not a layer!");
			}
		else{
			var thisLayer=eval('document.'+thisMenu);
			if(thisLayer.hidden){
				thisLayer.hidden=false;
				}
			}
		}
	else if(browserType=="ie4"){
		var thisStyle=eval("document.all."+thisMenu+".style");
		if(thisStyle.visibility!="visible"){
			thisStyle.visibility='visible';
			}
		}
	else{
		var thisStyle=eval("document.getElementById('"+thisMenu+"').style");
		if(thisStyle.visibility!="visible"){
			thisStyle.visibility='visible';
			}
		}
		addLayer(thisMenu);
	}

function hideMenu(thisMenu){
	//thisMenu="m"+menuObject.name.substr(1,menuObject.name.length)+"0";
	if (browserType=="n4"){
		if(thisMenu=='main'){
			alert("that's not a layer!");
			}
		else{
			var thisLayer=eval('document.'+thisMenu);
			if(!thisLayer.hidden){
				thisLayer.hidden=true;
				}
			}
		}
	else if(browserType=="ie4"){
		var thisStyle=eval("document.all."+thisMenu+".style");
		if(thisStyle.visibility!='hidden'){
			thisStyle.visibility='hidden';
			}
		}
	else{
		var thisStyle=eval("document.getElementById('"+thisMenu+"').style");
		if(thisStyle.visibility!='hidden'){
			thisStyle.visibility='hidden';
			}
		}
	}