var actLayer = "none";
var actImage = "none";
var menuTimer;
var version;
var layerOK = (document.all || document.layers || document.getElementById);

// Browser Check - not used for these js menus, but may be useful elsewhere
browserName = navigator.appName;
browserVersion = parseFloat (navigator.appVersion);
if (browserName == "Netscape" && browserVersion < 5)
	version = "NN";
else
	version = "OK";


// set the method of calling on layers
if (document.layers){
	layerVar = "document.layers"; styleVar = ""; visVar = "show";
}else if (document.all){
	layerVar = "document.all"; styleVar = ".style"; visVar = "visible";
}


// flip an image for the onMouseOver & onMouseOut
// name = the image name
// over= 1 or 0  (over & out, respectfully).
function flip(name,over) {
	if(over == 1){
		resetButtons();
	}
	if (document.images && document[name]){
				document[name].src = (over == 1) ? eval(name+"_on.src") : eval(name+"_off.src");
	}
}


// flip all the images (if any) back to "off" state
function resetButtons() {
	for(i = 0; i < buttonList.length; i++){
		if(document[layerList[i]]) document[layerList[i]].src = eval(layerList[i]+'_off.src');
	}
}


//hides submenus when leaving the link that opened one.
function hideChildren(num){
	for(var i=0; i<parents.length; i++){
		if(parents[i] == num)
			hideLayer(i);
	}	
}


// hide just one layer specfied by num (the index of layerList[])	 
function hideLayer(num) {
	if(layerOK && layerList[num]){
		if(document.all || document.layers){
			eval(layerVar + '["' + layerList[num] + 'layer"]' + styleVar + '.visibility="hidden"');
		}else if (document.getElementById){
			thisLayer = document.getElementById(layerList[num]+'layer');
			thisLayer.style.visibility = "hidden";
		}
	}
}


// called from clearMenus()
function hideAllLayers() {
	if(layerOK){
		var actLayer = "none";
		for (i = 0; i < layerList.length; i++) hideLayer(i);
		clearTimeout(menuTimer);
	}
}


// starts a timer that will close all menu layers & reset all the images
function clearMenus(image) {
	if(image) actImage = 'none';
	if(actImage=='none') menuTimer = setTimeout("resetAll()",TIMETILLCLOSE);
}


function resetAll() {
	var actLayer = "none";
	hideAllLayers();
	resetButtons();
}	   


// show the layer by making it "visible"
// num = the NUMBER of the layer to show (index of the layerList[] array)
// image = the NAME of the image to flip (optional)
function showLayer(num, image) {
	clearTimeout(menuTimer);
	if (layerOK && layerList[num]) {
		actLayer = layerList[num];
		
		// if this is a child menu, don't reset the buttons, or hide all the layers
		if(!parents[num]){
			resetButtons();
			hideAllLayers();
			if(image){
				flip(image, 1);
				actImage = image;
			}
		}
		if (document.all || document.layers) {
				eval(layerVar + '["' + layerList[num] + 'layer"]' + styleVar + '.visibility="visible"');
		} else if (document.getElementById) {
				thisLayer = document.getElementById(layerList[num]+'layer');
				thisLayer.style.visibility = "visible";
		}
	}
}


// prints out the html for the beginning of a layer
// always start a layer with this
function startLayer(name,top,left,visibility,z){
	if (document.layers){
		visibility = (visibility == 'visible') ? 'show' : 'hide';
		document.writeln('<layer name="'+name+'layer" id="'+name+'layer" top="'+top+'" left="'+left+'" visibility="'+visibility+'" z-index="'+z+'" onMouseOver="clearTimeout(menuTimer)" onMouseOut="clearMenus()">');
	} else if (document.all || document.getElementById) {
		document.writeln('<div name="'+name+'layer" id="'+name+'layer" style="position: absolute; top: '+top+'px; left: '+left+'px; visibility: '+visibility+'; z-index: '+z+';" onMouseOver="clearTimeout(menuTimer)" onMouseOut="clearMenus()">');
	}
  if(layerOK){
		document.writeln('<table class="layer" border="'+LAYER_BORDER+'" cellspacing="'+LAYER_SPACING+'" cellpadding="'+LAYER_PADDING+'">');
  }
}


// prints the html for one line of the menu
// you can use any other html you want in the layer, instead of this function
// linkname = the url of the link
// linkdescr = the test that will be displayed
// num = the index of the current layer (optional, use only if there are submenus of this menu)
// submenu = the sublayer that will be shown on mouseOver (optional, use only if there are submenus of this menu)
function writeLayerLine(linkname,linkdescr,linktitle,num,submenu){
	document.write('<tr>')

	// netscape 4.x section
	if(document.layers){
		document.write('<td class="layer">');
		document.write('<a class="ns4LayerLink" href="'+linkname+'" onMouseOver="');
			if(submenu){
				document.write('hideChildren('+num+'),showLayer('+submenu+')">');
			}else if(num){
				document.write('hideChildren('+num+')">');
			}else{
				document.write('">');
			}

	// good browser section
	}else{
		document.write('<td class="menulayer" title="'+linkdescr+'"  onclick="window.location=\''+linkname+'\'" onMouseOut="this.style.backgroundColor=\''+LINK_UNLIT+'\', this.style.textDecoration=\'none\'" onMouseOver="this.style.backgroundColor=\''+LINK_LIT+'\', this.style.textDecoration=\'underline\',  window.status=\''+linkname+'\'');
		if(submenu){
			document.write(', hideChildren('+num+'),showLayer('+submenu+')');
		}else if(num){
			document.write(', hideChildren('+num+')');
		}
		document.write('"><div class="layerLink" href="'+linkname+'">');
	}
	

	document.write(linktitle+'</a></td>');
	document.write('</tr>\n');
}


// prints the html for the end of the layer
// always end a layer with this
function endLayer(){
	if(layerOK){
		document.writeln('</table>');
	}
	if(document.layers){
		document.writeln('</layer>');
	}else if (document.all || document.getElementById){
		document.writeln('</div>');
	}
}
