﻿// adds sfhover class to li on mouse over because IE doesn't support the hover class on list items.
    var level2Width = 150;
    var maxWidth = 1000;
    var navL1s;
    var navL2s;
    var navL3s;
    navL1s = document.getElementById("LocalNav").childNodes;
	for (var i=0; i<navL1s.length; i++) {
	
		if(i==navL1s.length-1){
            			navL1s[i].className+=" last";
        		}    
		navL1s[i].onmouseover=function() {
		    if (is_ie)
		    {
				this.className+=" sfhover";	
			}
			 set2ndOffset(this);		
		}
		
		navL1s[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
		if (navL1s[i].firstChild && navL1s[i].firstChild.nextSibling && navL1s[i].firstChild.nextSibling.nextSibling) {
			
			navL1s[i].navL2s = navL1s[i].firstChild.nextSibling.nextSibling.childNodes;
			
			for (var j=0; j<navL1s[i].navL2s.length; j++) {

				navL1s[i].navL2s[j].onmouseover = function() {
				     
					 if (is_ie){
						this.className+=" sfhover";
					 }	
					 set3rdOffset(this);	
						
				}
				
				navL1s[i].navL2s[j].onmouseout=function() {
				    if (is_ie){
						this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					}	
				}
				
				if (navL1s[i].navL2s[j].firstChild && navL1s[i].navL2s[j].firstChild.nextSibling) {
					navL1s[i].navL2s[j].navL3s = navL1s[i].navL2s[j].firstChild.nextSibling.childNodes;
					for (var k=0; k<navL1s[i].navL2s[j].navL3s.length; k++) {
					
						navL1s[i].navL2s[j].navL3s[k].onmouseover = function() {
						    
						    if (is_ie)
								this.className+=" sfhover";
								
							
						}
						
						navL1s[i].navL2s[j].navL3s[k].onmouseout = function() {
						    if (is_ie)
								this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
						}
					}
					// adds p class to parent node to notify users that it has child nodes.
					navL1s[i].navL2s[j].className += " p";
				}
						
			}
		}
	}

// Ensures the first dropdown menus stay within the width of the website so as not to force scrolling at 800x600 resolution.
function set2ndOffset(navItem) {
    
	var navOffsetConstant = document.getElementById("LocalNav").offsetLeft;
	if (navItem.offsetLeft + level2Width - maxWidth > 0) {
		var tooWideBy = navItem.offsetLeft + level2Width - maxWidth;
		//document.title=tooWideBy;
		var padding = 0-tooWideBy;
		if (is_ie && !is_ie6up) {
			padding += 2;
		} else if (is_saf) {
			padding++;
		}
		if (navItem.firstChild && navItem.firstChild.nextSibling && navItem.firstChild.nextSibling.nextSibling
			&& navItem.firstChild.nextSibling.nextSibling.style && navItem.firstChild.nextSibling.nextSibling.style.margin ) {
			navItem.firstChild.nextSibling.nextSibling.style.margin = "0px 0px 0px " + padding + "px";
		}
	} else { // checks every time in case text has been resized
		if (navItem.firstChild && navItem.firstChild.nextSibling && navItem.firstChild.nextSibling.nextSibling
			&& navItem.firstChild.nextSibling.nextSibling.style && navItem.firstChild.nextSibling.nextSibling.style.margin) {
			navItem.firstChild.nextSibling.nextSibling.style.margin = "0px 0px 0px -1px";
		}
	}
}

// Ensures the second dropdown menus stay within the width of the website so as not to force scrolling at 800x600 resolution.
function set3rdOffset(navItem) {
    //try {document.title=navItem.parentNode.parentNode.offsetLeft;}catch(e){}
	if (navItem.firstChild && navItem.firstChild.nextSibling) {
	    
		if ((navItem.parentNode.parentNode.offsetLeft + (2*level2Width))  >   maxWidth) {
			//trace(true,true);
			
			var moveMarginTo = 0-level2Width-1;
			//document.title=moveMarginTo;
			navItem.firstChild.nextSibling.style.margin = "-18px 0px 0px " + moveMarginTo + "px";
		}
	}
}
