// Based on Matt Carroll's Suckerfish Menu at http://carroll.org.uk/sandbox/suckerfish/bones2.html.
// only ie needs the sfHover script. all need the accessibility script...
// Script thanks to http://www.brothercake.com/site/resources/scripts/onload/

sfHover = function() {
	var sfEls = document.getElementById("banner").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	}
}
mcAccessible = function() {
	var mcEls = document.getElementById("banner").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.className+=(this.parentNode.className.length>0? " ": "") + "sfhover"; //li < a:focus

			if(this.parentNode.parentNode.parentNode.parentNode.nodeName.toLowerCase() == "li") {
			   this.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; // li < div < ul < li < a:focus
			}

			if(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName.toLowerCase() == "li") {
			   this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < div < ul < li < ul < li < a:focus
			}

		}

		mcEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
			this.parentNode.className=this.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");

			if(this.parentNode.parentNode.parentNode.parentNode.nodeName.toLowerCase() == "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.toLowerCase() == "li") {
			   this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			}
		}
	}

// Date: 02/18/2011
// The following addition made by Marc Thompson to handle form input focus issues

	var mcEls = document.getElementById("banner").getElementsByTagName("input");
	for (var i=0; i<mcEls.length; i++) {
		mcEls[i].onfocus=function() {
			this.className+=(this.className.length>0? " ": "") + "sffocus"; //a:focus
			this.parentNode.className+=(this.parentNode.className.length>0? " ": "") + "sfhover"; //li < a:focus

			if(this.parentNode.parentNode.parentNode.parentNode.nodeName.toLowerCase() == "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.toLowerCase() == "li") {
			   this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			}
		}

		mcEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
			this.parentNode.className=this.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");

			if(this.parentNode.parentNode.parentNode.parentNode.nodeName.toLowerCase() == "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.toLowerCase() == "li") {
			   this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			}
		}
	}
// End code additions
}


if(window.addEventListener) {window.addEventListener('load', mcAccessible, false);} // gecko, safari, konqueror and standard
else if(document.addEventListener) document.addEventListener('load', mcAccessible, false); // opera 7
else if(window.attachEvent) { // win/ie
	window.attachEvent('onload', sfHover);
	window.attachEvent('onload', mcAccessible);
} else { // mac/ie5
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			existing();
			sfHover();
			mcAccessible();
		}
	} else {
		window.onload = function() {
			sfHover();
			mcAccessible();
		}
	}
}

// The following needs an element in the html with id="ieFix"
// e.g. <a href="#skipTarget" id="stickyMenuFix"></a>
$(window).load(function() {  // Sticky menu fix for IE browsers
	document.getElementById('stickyMenuFix').focus();
});



