/* navScript.js
 * A handful of functions for making dynamic navigation menus.  
 * Both functions must be called after the page loads:
 * <body onload="javascript:sfHover(); subHover();">
 * sfHover works on a ul with an id="mainNav"
 * subHover works on a ul with an id="subNav"
 */

 
/* sfHover() is adapted from the Sucker Fish Drop-Down Menu.
 * This function adds dynamic functionality to an unordered
 * list of "a" tags.  This script is dependant on a .css page
 * (nav.css) in order to function properly.  The current 
 * setup allows for only one layer of "hidden" elements, but 
 * this could be changed.  The top-level list items (<li>) in
 * the ul are displayed, and can display a sublist on a rollover.
 * the location and layout are defined in the css. */
function sfHover() {
	//get all the li in the ul to work with
	var sfEls = document.getElementById("mainNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {//for each li
		sfEls[i].onmouseover=function() {//add this function onMouseOver
			if(document.getElementsByTagName){//if DOM2
					var curVar = this;
			  	var subLinks = curVar.getElementsByTagName("li");//get any sublevels
					//if no sublevel, then change class to...
					if(subLinks.length == 0) this.className+=" hotNoSub";
					//if it has a sub level, change class too...
					else this.className+=" hotSub";
			}
		}
		sfEls[i].onmouseout=function() {//add this function to onMouseOut
			if(document.getElementsByTagName){//if DOM2
					var curVar = this;
					//get rid of either class name
					 this.className = this.className.replace(/(\s?hotSub\b)|(\s?hotNoSub\b)/g, "");
					}
				}
			}
		}

/* subHover() handles basic expanding/collapsing menus.  It uses
 * an ul of "a" tags containing no more than two layers.  On the
 * mouseover of a upperlevel li with a sub list, the sublist is displayed.
 * On a subsequent mouseout, the sublist is again hidden.  This function
 * depends on the use of a css sheet (nav.css) to function. */
function subHover() {
	//get the li from the subNav
	var sfEls = document.getElementById("subNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {//for each one
		sfEls[i].onmouseover=function() {//add this fucntion onmouseover
			if(document.getElementsByTagName){
					var curVar = this;
					//add "hot" to classname
					this.className+=" hot";
			}
		}
		/* this part made the sub menus collapse on mouse out.
		 * uncomment to add this back in 
		sfEls[i].onmouseout=function() {//add this fucntion onmouseout
			if(document.getElementsByTagName){
					var curVar = this;
					//remove "hot" from class
					this.className = this.className.replace(/(\s?hot\b)/g, "");
					}
				}*/
			}
		}