// copyright Paul Appleby, Toronto, ON, Canada

var timer=null;
var item;
var myObj="";
var child;
var thechild;
var thischild;
var showparent;
var killparent;
var y;// Needed in moveup() and movedown().
var ns4_href="";// Need this as the link to use with the capture Event in each layer and the clickit() function since NS4 doesn't use onClick in a layer or TD.


function clickit(){// For NS4
	if (ns4_href=="#"){return;}
	else{document.location.href=ns4_href;}
}

function clickme(x,y,z){// For IE5 and NS6; especially so IE 5 on Mac won't reload if the link ="#";
	if (x=="#"){
		return;
	}
	else{
		document.location.href=x;
		killAll();// killAll is needed for IE5 Mac, which otherwise, after linking and using the back button, leaves the menus expanded.
		// and the rest is a further fix for IE5 Mac which furthermore leaves the td's class as navover and the bgcolor as the mouseover color when we use the back buttton after going to the link.. 
		if (document.all)x=eval("document.all."+y);
		x.bgColor=z;
		x.className="nav";	
	}
}

//This and movedown is the only way to get the font colour to change by "onmouseover" in NS4 which cannot access the font colour dynamically.
//Instead we use two layers, identical except for their font color. The one written last in the HTML is the one to appear on top and it is moved away up and then back down.
function moveup(m,l){
	y=eval("document.layers[\'"+m+"\'].document.layers[\'"+l+"over\'].top");
	eval("document.layers[\'"+m+"\'].document.layers[\'"+l+"out\'].top=-400");
}
function movedown(m,l){
	eval("document.layers['"+m+"'].document.layers[\'"+l+"out\'].top=y");
}

function show(item){
	if (item!=""){
		if (timer){
			clearTimeout(timer); // Need to clear the timer that was started in hide() and counting down to hide the sub, otherwise the sub below that we want to keep open will be killed.
		}
		if (document.all){
			eval("document.all." + item +".style.visibility='visible'");
			for (i=0;i<parents.length;i++){
				if (item==parents[i]){;
					if (parents[parents[i]][0]!=null){
						theparent=parents[parents[i]][0];//This items parent.
						eval("document.all." + theparent +".style.visibility='visible'");
						//if (theparent!=null){
							//grandparent=parents[theparent][0];//This items parent's parent.
							//if (grandparent!=null){ 
								//eval("document.all." + grandparent +".style.visibility='visible'");
							//}
						//}
					}
				}
			}
		}
		if (document.layers){
			eval("document.layers['" + item + "'].visibility='visible'");
			for (i=0;i<parents.length;i++){
				if (item==parents[i]){;
					if (parents[parents[i]][0]!=null){
						theparent=parents[parents[i]][0];//This items parent.
						eval("document.layers['" + theparent + "'].visibility='visible'");
						//if (theparent!=null){
							//grandparent=parents[theparent][0];//This items parent's parent.
							//if (grandparent!=null){ 
								//eval("document.all." + grandparent +".style.visibility='visible'");
							//}
						//}
					}
				}
			}
		}
		if (document.getElementById  && !document.all){
			myObj=eval("document.getElementById('" + item + "').style");
			myObj.visibility="visible";
					for (i=0;i<parents.length;i++){
				if (item==parents[i]){;
					if (parents[parents[i]][0]!=null){
						theparent=parents[parents[i]][0];//This items parent.
						eval("document.getElementById('" + theparent + "').style.visibility='visible'");
						//if (theparent!=null){
							//grandparent=parents[theparent][0];//This items parent's parent.
							//if (grandparent!=null){ 
								//eval("document.all." + grandparent +".style.visibility='visible'");
							//}
						//}
					}
				}
			}
		}
	}
}
 
function showLayer(m,l){// This and hideLayer is the only way to get the font colour to change by "onmouseover" in NS4 which cannot access the font colour dynamically.
	if (document.layers){
		eval("document.layers['" + m + "'].document.layers['" + l + "'].visibility='visible'");
	}
}
function hideLayer(m,l){
	if (document.layers){
		eval("document.layers['" + m + "'].document.layers['" + l + "'].visibility='inherit'");	
	}
}

function hide(theitem){
	item=theitem;
	if (item!=""){
		for (i=0; i<parents.length; i++){
			if (theitem==parents[parents[i]][0]){
				thechild=parents[i];
			}
			else {
				thechild=null;
			}
		}
		if (document.all){
			if (thechild==null || eval("document.all." + thechild +".style.visibility='hidden'")){// If the child ...
				timer=setTimeout("hideit(item)", 250);
			}
			else{
				hideit(item);
			}
		}
		if (document.layers){
			if (thechild==null || eval("document.layers['" + thechild + "'].visibility='hidden'")){
			timer=setTimeout("hideit(item)", 250);
			}
			else{
				hideit(item);
			}
		}
		if (document.getElementById  && !document.all){
			if (thechild==null || eval("document.getElementById('" + thechild + "').style.visibility=='hidden'")){//If the child ...
				timer=setTimeout("hideit(item)", 250);
			}
			else{
				hideit(item);
			}
		}
	}
}

function hideit(item){
	if (document.all){
		eval("document.all." + item +".style.visibility='hidden'");
	}
	if (document.layers){
		eval("document.layers['" + item + "'].visibility='hidden'");
	}
	if (document.getElementById  && !document.all){
		myObj=eval("document.getElementById('" + item + "').style");
		myObj.visibility="hidden";
	}
}

function hidechild(item){
	if (document.all){	
		eval("document.all." + item +".style.visibility='hidden'");
	}
		
	if (document.layers){
		eval("document.layers['" + item + "'].visibility='hidden'");
	}
		
	if (document.getElementById  && !document.all){
		myObj=eval("document.getElementById('" + item + "').style");
		myObj.visibility="hidden";
	}
}
 
function killAll(){
	clearTimeout(timer);
	if (document.all){
		for (i=0; i<allmenus.length; i++){
			eval("document.all."+allmenus[i]+".style.visibility='hidden'");
		}
	}
	if (document.layers){
		for (i=0; i<allmenus.length; i++){
			eval("document.layers['" + allmenus[i] + "'].visibility='hidden'");
		}
	}
	if (document.getElementById  && !document.all){
		for (i=0; i<allmenus.length; i++){
			myObj=eval("document.getElementById('" + allmenus[i] + "').style");
			myObj.visibility="hidden";
		}
	}
	
}

function killParent(item){
	if (document.all){
		for (i=0; i<allmenus.length; i++){
			eval("document.all."+allmenus[i]+".style.visibility='hidden'");
		}
	}
	if (document.layers){
		for (i=0; i<allmenus.length; i++){
			eval("document.layers['" + allmenus[i] + "'].visibility='hidden'");
		}
	}
	if (document.getElementById  && !document.all){
		for (i=0; i<allmenus.length; i++){
			myObj=eval("document.getElementById('" + allmenus[i] + "').style");
			myObj.visibility="hidden";
		}
	}
	
}
