// JavaScript Document<script type="text/javascript">

var sfHover =
{
	szLastMenu: "",
	
	getParent: function( oEl )
	{
		for (oItr = oEl; oItr; oItr = oItr.parentNode)
		{
			if (oItr.parentNode. id == this.szRootID)
				return oItr;
		}
		
		return null;
	},
	
	getParentAnchor: function( oEl )
	{
		oParent = this.getParent( oEl );
		
		if (oParent)
		{
			for (oItr = oParent.firstChild; oItr; oItr = oItr.nextSibling)
			{
				if  (oItr.tagName == "A")
					return oItr;
			}
		}
		
		return null;
	},
	
	setListStyle: function( oChild, szNewState )
	{
		aLists = sfHover.getParent(oChild).getElementsByTagName("UL");
		if (aLists[0])
			aLists[0].style.left=szNewState;
	},
	
	findListByClassName: function( szClassName )
	{
		oRootUL = document.getElementById(this.szRootID);
		
		if (!oRootUL)
			return NULL;
		
		 for (oItr = oRootUL.firstChild; oItr; oItr = oItr.nextSibling)
		 {
		 	if (oItr.className == szClassName)
		 		return oItr;
		 }
	},
	
	closeAllMenus: function()
	{
		oRootUL = document.getElementById(this.szRootID);
		
		if (!oRootUL)
			return NULL;
		
		 for (oItr = oRootUL.firstChild; oItr; oItr = oItr.nextSibling)
		 {
		 	if (oItr.tagName == "LI")
		 		this.setListStyle( oItr, "-999em" ); 
		 }
	},
	
	init: function(szRootID)
	{				
		var sfEls = document.getElementById(szRootID).getElementsByTagName("LI");
		
		this.szRootID = szRootID;
		
		// Assign mouse reactions to menus
		for (var i=0; i<sfEls.length; i++) 
		{								
			sfEls[i].onmouseover=function() 
			{														
				if (sfHover.getParentAnchor(this))
				{
					sfHover.getParentAnchor(this).style.backgroundPosition = "0 -27px";
					
					if (this.className)
					{		
						sfHover.setListStyle(this,"auto");					

						if (sfHover.szLastMenu && sfHover.szLastMenu != this.className)
						{
							//alert(sfHover.szLastMenu);
							sfHover.setListStyle(sfHover.findListByClassName(sfHover.szLastMenu),"-999em");							
						}
							
						sfHover.szLastMenu = this.className;						
					}					
				}				
				
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() 
			{				
				this.className=this.className.replace(new RegExp(" *sfhover\\b"), "");				
				if (sfHover.getParentAnchor(this))
				{
					sfHover.getParentAnchor(this).style.backgroundPosition = "0 0px";														
					
					if (!this.className)
					{						
						sfHover.setListStyle(this,"-999em");
					}
				}				
			}
		}
		
		// ... and to the header bar
		oHeader = document.getElementById("header");
		
		if (oHeader)		
			oHeader.onmouseover=function() { sfHover.closeAllMenus(); }
	}
}

