/**************************************
 *** PrevsiouMaps Hover used for IE6 ***
 **************************************/
prevHover = function() {
	var sfEls = document.getElementById("previousdropid").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" prevhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" prevhover\\b"), "");
		}
	}
}
/*

It's unlikely IE6 even works any more...

if (version < 7) {window.attachEvent("onload", prevHover);}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			if (this.className == "listheader sfhover") {
				this.style.background = "#fff";
				this.style.borderTop = "1px solid #fff";
				this.style.borderBottom = "1px solid #fff";
			}
		}

		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (version < 7) {window.attachEvent("onload", sfHover);}

sfHover2 = function() {
	var sfEls = document.getElementById("addsites").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover2";
			if (this.name == "filters") {
				this.className = ""
			}
			if (this.className == "listheader sfhover2") {
				this.style.background = "#fff";
				this.style.borderTop = "1px solid #fff";
				this.style.borderBottom = "1px solid #fff";
			}
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover2\\b"), "");
		}
	}
}  
if (version < 7) {window.attachEvent("onload", sfHover2);}
*/

function disableMenu(){
	$("#nav li ul").hide();
}
function enableMenu(){
	$("#nav li ul").show();
}


 
// Adds keyboard accessibility for the indicator menu and the sites menu by adding focus and blur events that show and hide the menu
// Also in index.css the focus pseudo class is added for styling
keyboardAccessible = function() {
	// Indicator Menu
	if (document.getElementById("nav")) {
		var mcEls = document.getElementById("nav").getElementsByTagName("A");
		for (var i=0; i<mcEls.length; i++) {
			mcEls[i].onfocus=function() {
				this.className+=(this.className.length>0? " ": "") + "sffocus"; //a:focus
				this.parentNode.parentNode.className+=(this.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < a:focus
				if(this.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < a:focus
					if(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
						this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < ul < li < a:focus
					}
				}
				// Used for when there are scroll divs in the menu
				// Only difference from above if is went up the hierarchy by 2 parentNodes in each line and className setting
				else if(this.parentNode.parentNode.parentNode.parentNode.nodeName == "DIV") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < a:focus
					if(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
						this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < ul < li < a:focus
					}
				}
			}
			mcEls[i].onblur=function() {
				this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
				this.parentNode.parentNode.className=this.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				if(this.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
					if(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
						this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
					}
				}
				// Used for when there are scroll divs in the menu
				// Only difference from above if is went up the hierarchy by 2 parentNodes in each line and className setting
				if(this.parentNode.parentNode.parentNode.parentNode.nodeName == "DIV") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
					if(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
						this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
					}
				}
			}
		}
	}

	// For horizontal menus, so sites menu and widgets indicator and sites menus
	var uls = jQuery(".horMenu");
	for (var j=0; j<uls.length; j++) {
		var mcEls = jQuery(uls[j]).find("a");
		for (var i=0; i<mcEls.length; i++) {
			mcEls[i].onfocus=function() {
				this.className+=(this.className.length>0? " ": "") + "sffocus"; //a:focus
				this.parentNode.parentNode.className+=(this.parentNode.parentNode.className.length>0? " ": "") + "sfhover2"; //li < a:focus
				if(this.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover2"; //li < ul < li < a:focus
					if(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
						this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover2"; //li < ul < li < ul < li < a:focus
					}
				}
				else if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					// for when there is no third level in the menu we the elements are a little different
					// so we need to adjust the 5th parent node because that's the LI element instead of the 4th.
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover2"; //li < ul < li < a:focus
				}
			}
			mcEls[i].onblur=function() {
				this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
				this.parentNode.parentNode.className=this.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover2\\b"), "");
				if(this.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover2\\b"), "");
					if(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
						this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover2\\b"), "");
					}
				}
				else if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					// for when there is no third level in the menu we the elements are a little different
					// so we need to adjust the 5th parent node because that's the LI element instead of the 4th.
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover2\\b"), "");
				}
			}
		}
	}
}

// only ie needs the sfHover script. all need the accessibility script...
if(window.addEventListener) { window.addEventListener('load', keyboardAccessible, false);} // gecko, safari, konqueror and standard
else if(document.addEventListener) document.addEventListener('load', keyboardAccessible, false); // opera 7
else if(window.attachEvent) { // win/ie
	//window.attachEvent('onload', sfHover);
	window.attachEvent('onload', keyboardAccessible);
} else { // mac/ie5
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			//existing();
			//sfHover();
			keyboardAccessible();
		}
	} else {
		window.onload = function() {
			//sfHover();
			keyboardAccessible();
		}
	}
}


