/******************************************************************************
 * FUNCTION: debugAlert
 * PURPOSE: This function will add the sfhover class to all suckerfish list
 *          items.  This class will allow IE to mimick the hover event.
 * ARGS:
 *	NONE
 *****************************************************************************/
sfHover = function()
{
	// get the suckerfish menu
	var sf = document.getElementById("suckerfishnav");
	
	// IF we don't have a suckerfish menu
	//  return
	// ENDIF
	if (sf == null)
	{
		return;
	}

	// get all of the menu list items
	var sfEls = sf.getElementsByTagName("LI");

	// LOOP through all of the menu elements
	//  add the mouse over function
	//  add the mouse out function
	// ENDLOOP
	for (var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover=function()
		{
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function()
		{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/******************************************************************************
 * FUNCTION: mcAccessible
 * PURPOSE: This function adds the ability to tab through the menus
 * ARGS:
 *	NONE
 *****************************************************************************/
mcAccessible = function()
{
	// get the suckerfish menu
	var sf = document.getElementById("suckerfishnav");
	
	// IF we don't have a suckerfish menu
	//  return
	// ENDIF
	if (sf == null)
	{
		return;
	}

	// get all of the menu list items
	var mcEls = sf.getElementsByTagName("A");

	// LOOP through all of the menu elements
	// ENDLOOP
	for (var i=0; i<mcEls.length; i++)
	{
		// define an onfocus function for the element
		mcEls[i].onfocus=function()
		{
			//a:focus
			this.className+=(this.className.length>0? " ": "") + "sffocus";

			//li < a:focus
			this.parentNode.className+=(this.parentNode.className.length>0? " ": "") + "sfhover";

			// IF the great-grand parent is a list item
			// ENDIF
			if(this.parentNode.parentNode.parentNode.nodeName == "LI")
			{
				//li < ul < li < a:focus
				this.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover";

				// IF great-great-great grand parent is a list item
				// ENDIF
				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? " ": "") + "sfhover";
				}
			}
		}

		// define an onblur function for the element
		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 the great grandparent node is a list item
			// ENDIF
			if(this.parentNode.parentNode.parentNode.nodeName == "LI")
			{
				// remove the sfhover class
				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				// IF great-great-great grand parent is a list item
				// ENDIF
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI")
				{
					// remove the sfhover class
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				}
			}
		}
	}
}

// IF the browser is gecko, safari, konqueror or standard
//  add the keyboard accesible function via the window addEventListener function
// ELSE IF the browser is an opera 7 browser
//  add the keyboard accesible function via the document addEventListener function
// ELSE IF the browser is windows ie
//  add the keyboard accesible function via the document addEventListener function
//  add the menu hover function via the document addEventListener function
// ELSE IF the browser is windows ie
//  IF the current onload function is defined
//   add the existing function
//   add the keyboard accesible function via the window onload function
//   add the menu hover function via the window onload function
//  ELSE
//   add the keyboard accesible function via the window onload function
//   add the menu hover function via the window onload function
//  ENDIF
// ENDIF
// NOTE: thanks http://www.brothercake.com/site/resources/scripts/onload/
if(window.addEventListener)
{
	window.addEventListener('load', mcAccessible, false);
}
else if(document.addEventListener)
{
	document.addEventListener('load', mcAccessible, false);
}
else if(window.attachEvent)
{
	window.attachEvent('onload', sfHover);
	window.attachEvent('onload', mcAccessible);
}
else
{
	if(typeof window.onload == 'function')
	{
		var existing = onload;
		window.onload = function()
		{
			existing();
			sfHover();
			mcAccessible();
		}
	}
	else
	{
		window.onload = function()
		{
			sfHover();
			mcAccessible();
		}
	}
}
