// JavaScript Document

/*
..........................................................
	nav_submenu_trigger.js
..........................................................

	Required by the main menu for use with IE Win.

	Used to:
	
	(a) Replicate the :hover selector in IE Win,
		where it is unsupported.
	
	(b) Work around an IE Win diplay bug where select boxes
		float above layers, regardless of their z setting.
		This is overcome by hiding an element with a set id
		that contains the select boxes.
		

*/
function getElementByClass(_clsName){
	var els, matches = new Array(), i = 0;
	els = document.getElementsByTagName('span');
	for (i; i < els.length; i++)
		if (els[i].className == _clsName) 
			matches[matches.length] = els[i];
	return matches;
}


function toggleVisible(_clsName) {
	var btns = _clsName;
	for(var i = 0; i < btns.length; i++) {
		btns[i].style.visibility = (btns[i].style.visibility != 'hidden') ? 'hidden': 'visible';
	}
	return true;
}

startNav = function() {
	// test for document.all, which is the MS proprietary ver of getElementById
	// appears to only be supported by IE, which is where the workaround is to be applied.	
	
	if (document.all&&document.getElementById) {

		// id for ul containing the nav
		var navRoot = document.getElementById("navigation").getElementsByTagName('LI');

		// turn on feat. (b) ? 
		var hideInIE = true;  // turn feat. (b) on
		// id for element to hide
		// if the element to be hidden (ie, the div "subfilter_hider") exists....

		if (getElementByClass("select-hider")) {
			// assign it to a variable
			var subFilter = getElementByClass("select-hider");
			
		// ...otherwise...
		} else {
			// ...give the variable a temp value (we won't be using the var)
			var subFilter = this;
			// and turnm off hiding in IE, as we won't be requiring it
			hideInIE = false;
		}

		// loop through children of navRoot...
		for (var i=0; i< navRoot.length; i++) {
			var node = navRoot[i];
			// ...and test to see if the child is a list item
			if (node.nodeName=="LI") {
				// run this code if hideInIE is true
				if(hideInIE) {				
					// set flag that records if the li has a child ul (ie. has a submenu)
					node.hasChildUL = false;								
					// loop to see if the node contains a ul
					for (j=0; j<node.childNodes.length; j++) {
						var kiddyNode = node.childNodes[j];
						// trip the flag if it does
						if (kiddyNode.nodeName == "UL") {
							node.hasChildUL = true;
						}
					}
				}
				// mouse events if there is a submenu and we have div hiding on for IE
				if (node.hasChildUL&&hideInIE){
					node.onmouseover=function() {
						this.className+="jshover";
						// hide id
						toggleVisible(subFilter);
 				 	}
  					node.onmouseout=function() {
  						this.className=this.className.replace("jshover", "");
						// hide id
						toggleVisible(subFilter);
   					}
				
				// ...otherwise do this
				} else {
					node.onmouseover=function() {
						this.className+="jshover";			
 				 	}
  					node.onmouseout=function() {
  						this.className=this.className.replace("jshover", "");
					}
				}
			}
  		}
	}
}
window.onload=startNav;