/* ---------------------------------------------
Keyboard accessible dropdown menu
Author:Adriana Palazova
Version:22 February 2009
last rev.: 3 March 2009
gratitude to Matthew Carroll - http://carroll.org.uk/sandbox/suckerfish/bones2.html
and
Alan Gresley - http://css-class.com/articles/ursidae/

The original version of this Javascript can be found at
http://adipalaz.awardspace.com/experiments/css/accessible_ddmenu_test.html.
This version has been modified to meet Florida DOH standards.
------------------------------------------------ */
var menuID = "ddmenu";

function accessible_menus_ie() {
  ///////////////////////////////////////
  // gratitude to Matthew Carroll - http://carroll.org.uk/ - http://carroll.org.uk/sandbox/suckerfish/bones2.html
  ///////////////////////////////////////
	var sfEls = document.getElementById(menuID).getElementsByTagName("LI");

	for (var i=0; i<sfEls.length; i++) {

		sfEls[i].onmouseover=function() {

			this.className+=(this.className.length>0? " ": "") + "sfhover";

			this.parentNode.className+=(this.parentNode.className.length>0? " ": "") + "sfhover";

		}

		sfEls[i].onmouseout=function() {

			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");

			this.parentNode.className=this.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");

		}

	}

	var mcEls = document.getElementById(menuID).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? " ": "") + "sffocusparent"; //li < a:focus

			this.parentNode.parentNode.className+=(this.parentNode.parentNode.className.length>0? " ": "") + "sffocusparent"; //ul < li < a:focus

			if(this.parentNode.parentNode.parentNode.nodeName == "LI") { //li < ul < li < a:focus

				this.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sffocusparent"; //li < ul < li < a:focus

				this.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sffocusparent"; //ul < li < ul < li < a:focus

				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {  //li < ul < li < ul < li < a:focus

					this.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sffocusparent"; //li < ul < li < ul < li < a:focus

					this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sffocusparent"; //#menu < li < 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("( ?|^)sffocusparent\\b"), "");

			this.parentNode.parentNode.className=this.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\b"), "");

			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {

				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\b"), "");

				this.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\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("( ?|^)sffocusparent\\b"), "");

					this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\b"), "");

				}

			}

		}

	}

}

function accessible_menus_non_ie() {

	var mcEls = document.getElementById(menuID).getElementsByTagName("A");

	for (var i=0; i<mcEls.length; i++) {
	
		mcEls[i].onfocus=function() {

			this.className = this.className ? this.className + " sffocus" : "sffocus"; //a:focus

			this.parentNode.className = this.parentNode.className ? " sffocusparent" : "sffocusparent"; //li < a:focus

			this.parentNode.parentNode.className = this.parentNode.parentNode.className ? " sffocusparent" : "sffocusparent"; //ul < li < a:focus

			if(this.parentNode.parentNode.parentNode.nodeName == "LI") { //li < ul < li < a:focus

				this.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.className ? " sffocusparent" : "sffocusparent"; //li < ul < li < a:focus

				this.parentNode.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.parentNode.className ? " sffocusparent" : "sffocusparent"; //ul < li < ul < li < a:focus

				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {  //li < ul < li < ul < li < a:focus

					this.parentNode.parentNode.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.parentNode.parentNode.className ? " sffocusparent" : "sffocusparent"; //li < ul < li < ul < li < a:focus

					this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className ? " sffocusparent" : "sffocusparent"; //ul < li < 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("( ?|^)sffocusparent\\b"), "");

			this.parentNode.parentNode.className=this.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\b"), "");

			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {

				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\b"), "");

				this.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\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("( ?|^)sffocusparent\\b"), "");

					this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sffocusparent\\b"), "");

				}
			}
		}
	}
}

// only ie needs the sfHover script. all need the accessibility script...

//http://www.brothercake.com/site/resources/scripts/onload/
//GO1.1
///////////////////////////////////////
//  Generic onload by Brothercake
//  http://www.brothercake.com/
///////////////////////////////////////


//setup onload function
if(typeof window.addEventListener != 'undefined')
{
	//.. gecko, safari, konqueror and standard
	window.addEventListener('load', accessible_menus_non_ie, false);
}
else if(typeof document.addEventListener != 'undefined')
{
	//.. opera 7
	document.addEventListener('load', accessible_menus_non_ie, false);
}
else if(typeof window.attachEvent != 'undefined')
{
	//.. win/ie
	window.attachEvent('onload', accessible_menus_ie);
}

//** remove this condition to degrade older browsers
else
{
	//.. mac/ie5 and anything else that gets this far
	
	//if there's an existing onload function
	if(typeof window.onload == 'function')
	{
		//store it
		var existing = onload;
		
		//add new onload handler
		window.onload = function()
		{
			//call existing onload function
			existing();
			
			//call accessible_menus_ie onload function
			accessible_menus_ie();
		};
	}
	else
	{
		//setup onload function
		window.onload = accessible_menus_non_ie;
	}
}
