
// Make the elements in the list react to mouse hover, like anchors do, so that :hover can be used in CSS

makeHoverable = function(elementList) {
	for (var i=0; i<elementList.length; i++) {
		elementList[i].onmouseover=function() {
			this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		elementList[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	}
}

// Make the elements in the list react to tab focus as if they had been mouse hovered (and :hover styles)

makeTabHoverable = function(elementList) {
	for (var i=0; i<elementList.length; i++) {
		elementList[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.nodeName == "LI") {
				this.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < a:focus
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
  	      			this.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < ul < li < a:focus
  	       		}
  	     	}
  		}
  	   	elementList[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.nodeName == "LI") {
  	     		this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
  	           	if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
  	           		this.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
  	          	}
  	      	}
  	   	}
  	}
}

// Make all li tags within the toolbar and tabbar hoverable

sfHover = function() {
 	var el = document.getElementById("toolbarNav");
 	if (el) makeHoverable(el.getElementsByTagName("LI"));

	el = document.getElementById("tabbarNav");
 	if (el) makeHoverable(el.getElementsByTagName("LI"));
}

// Make all anchor tags within the toolbar and tabbar tab-hoverable

mcAccessible = function() {
	var el = document.getElementById("toolbarNav");
	if (el) makeTabHoverable(el.getElementsByTagName("A"));

	el = document.getElementById("toolbarAct");
	if (el) makeTabHoverable(el.getElementsByTagName("A"));

	el = document.getElementById("tabbarNav");
	if (el) makeTabHoverable(el.getElementsByTagName("A"));
}
	
// Only IE needs the sfHover script - other environments conform to the standard anyway. 
// All need the accessibility script
// Thanks to: http://www.brothercake.com/site/resources/scripts/onload/

if(window.addEventListener) {								// gecko, safari, konqueror and standard
	window.addEventListener('load', mcAccessible, false); 
}
else if(document.addEventListener) {						// opera 7
	document.addEventListener('load', mcAccessible, false); 
}
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();
        }
    }
}

