// JavaScript Document

function SetMenuAwareness() // SetMenuAwareness()
{
	var _body = document.getElementsByTagName("BODY")[0];
	
	if(!_body){ return; }
	
	_body.setAttribute("id", "body_tag");

	var oLi = document.getElementById("main-nav").getElementsByTagName("LI");

	//# here we go mapping the Main Navigation into oMenuItem.
	//# oMenuItem is level 0 with oMenuItem[].Items being an object array of nested LIs.
	//# That being the case, oMenuItem[].Pane is the first nested UL, which contains the LIs.
	//# Dependent on some /config/user_defined/js_main_library.js functions;
	//# UPDATE: as of 2009-07-08, these functions are part of /js/main_library.js
	//#		getCollectionByObject()
	//#		GetObjectDimensions()
	//#		GetDimensions()
	//#		FindPos()
	var oMenuItem = new Array();
	var x = 0;
	for( var i = 0; i < oLi.length; i++ )
	{
		if( parseInt(oLi[i].getAttribute("level")) === 0 )
		{
			oMenuItem[x] = oLi[i];
			oMenuItem[x].Pane = getCollectionByObject(oLi[i], "UL");
			for( var z = 0; z < oMenuItem[x].Pane.length; z++ )
			{
				oMenuItem[x].Pane[z].Items = getCollectionByObject(oMenuItem[x].Pane[z], "LI");
				oMenuItem[x].Pane[z].Width = GetObjectDimensions( oMenuItem[x].Pane[z] )[0];
			}
			if(oMenuItem[x].Pane[0]){oMenuItem[x].Pane[0].style.visibility = "hidden"};

			oMenuItem[x].onmouseover=function()
			{
				if(this.Pane[0])
				{
					var bw = GetDimensions(_body.id)[0];
					var offset = FindPos(this)[0];
					
					/*
					alert(
						(this.Pane[0].Width+offset)+" : "+
						bw+" : "+
						( offset - (this.Pane[0].Width - (bw - offset - 20) ) + this.Pane[0].Width )
					);
					*/
					
					this.Pane[0].style.marginLeft = ( (this.Pane[0].Width + offset) > bw )
						? "-"+( this.Pane[0].Width - (bw - offset - 23) )+"px"
						: "0px"
					;

					this.Pane[0].style.visibility = "visible";
				}
				
				if (window.attachEvent){ this.className+="sfhover"; }
			}
			
			oMenuItem[x].onmouseout=function()
			{
				if(this.Pane[0]){ this.Pane[0].style.visibility = "hidden"; }
				
				if (window.attachEvent){ this.className=this.className.replace("sfhover", ""); }
			}
			
			x++;
		}
	}
}
SetMenuAwareness();
