// Note: basic browser sniffer setup to detect non-IE browsers (function sniffSniff()).  Else If statements will need to be
//		added as more exceptions are found.
//
// Updated: 7-22-03 - Added in sniffer and nullcheck in loops for Mozilla compatibility.

// General Declarations
var cn = "nav"  //global variable for class name
var isOver = false; 
var timoutID = 100;
var timoutDuration = 1000; //length of time that the menus pop up/appear
var startLoop = 0; //default starting point for the for-next loops (IE default)

// Functions and Subroutines
function setNavProps(el,lvl){ 
	var oNodes = el.childNodes; // set main variable and class; note that "el" must be a "UL" element
	(oNodes.item(0) && oNodes.item(0).tagName!=null) ? startLoop = 0 : startLoop = 1;
	el.className = cn+lvl;
	for (var x=startLoop;x<oNodes.length;x++){
		if (oNodes[x].tagName!=null && oNodes[x].tagName.toLowerCase()=="li"){ // verify is LI tag, if so - set class for LI element, assign Javascript refs
			oNodes[x].className = cn+lvl;
			oNodes[x].onmouseover=showNav;
			oNodes[x].onmouseout=hideNav;
			for (var y=startLoop;y<oNodes[x].childNodes.length;y++){ // loop through childNodes for the tags
				if (oNodes[x].childNodes[y] && oNodes[x].childNodes[y]["tagName"]){ // if is an A tag, set its class
					if (oNodes[x].childNodes[y].tagName.toLowerCase()=="a") {
						oNodes[x].childNodes[y].className=cn+lvl
					} else if (oNodes[x].childNodes[y].tagName.toLowerCase()=="ul"){ // otherwise, recurse
						setNavProps(oNodes[x].childNodes[y],lvl+1);
					}
				}
			}
		}
	}
}
function showNav(){ 
	el=this
	//alert(el.tagName + ": " + el.offsetTop + "\n" + el.offsetParent.tagName + ": " + el.offsetParent.offsetTop + "\n" + el.offsetParent.offsetParent.tagName + ": " + el.offsetParent.offsetParent.offsetTop);
	//window.status=el.tagName + ": " + el.offsetTop + " " + el.offsetParent.tagName + ": " + el.offsetParent.offsetTop + " " + el.offsetParent.offsetParent.tagName + ": " + el.offsetParent.offsetParent.offsetTop
	isOver = true; // let the world know not to hide anything
	clearTimeout(timoutID); // stop the hiding of layers (if applicable)
	hideAllNavItems(el); // hide all lower elements
	for (var x=startLoop;x<el.childNodes.length;x++){ // show the current request
		if (el.childNodes[x] && el.childNodes[x]["tagName"] && el.childNodes[x].tagName.toLowerCase()=="ul"){ // make sure that we're looking at the UL element
			if (el.childNodes[x]["className"] && el.childNodes[x].className.substr(el.childNodes[x].className.length-1,1)>0) { //if the right-most number is > 2 & position != absolute (removed "!= absolute" part)
					// set position=absolute, top & left props
					el.childNodes[x].style.position = 'absolute';
					o = el;
					ox=o.offsetLeft;oy=o.offsetTop;
					 while (o.offsetParent!=null){ //recursish pulling of positions.
						//alert(o.tagName + ": " + o.offsetLeft);
						o=o.offsetParent;
						oy+=o.offsetTop;
						ox+=o.offsetLeft;
					}
					el.childNodes[x].style.top = oy + el.offsetHeight;
					//el.childNodes[x].style.top = el.offsetTop + el.offsetHeight; //oy - 55;
					el.childNodes[x].style.left = ox; //ox - 140;
					//el.childNodes[x].style.left = el.offsetLeft; //ox - 140;
					//el.childNodes[x].style.width = el.offsetWidth;
			}
			el.childNodes[x].style.display = "block"; // show the element
		}
	}
}
function hideAllNavItems(el){
	for (var y=startLoop;y<el.parentNode.childNodes.length;y++){
		if (el.parentNode.childNodes[y] && el.parentNode.childNodes[y]["tagName"] && el.parentNode.childNodes[y].tagName.toLowerCase()=="li"){
			for (var z=startLoop;z<el.parentNode.childNodes[y].childNodes.length;z++){
				if (el.parentNode.childNodes[y].childNodes[z] && el.parentNode.childNodes[y].childNodes[z]["tagName"] && el.parentNode.childNodes[y].childNodes[z].tagName.toLowerCase()=="ul"){
					el.parentNode.childNodes[y].childNodes[z].style.display = "none";
				}
			}
		}
	}
}
function hideNav(){
	el = this
	isOver = false;
	(el.childNodes.length>2) ? el=el : el=el.parentNode.parentNode; // verify not at lowest level; if so, step up a couple of levels.
	var f="if(!isOver){hideAllNavItems(el)}";
	timoutID = setTimeout(f,timoutDuration) // set the timeout
}
