// JavaScript Document

function 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;
	//#		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");
			oMenuItem[x].Width = GetObjectDimensions( oMenuItem[x] )[0];
			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];
					
					var margin = 0;
					if( typeof(is_ie) != 'undefined' ){ margin = this.Width - 10; } 
					
					this.Pane[0].style.marginLeft = ( (this.Pane[0].Width + offset) > bw )
						? "-"+( this.Pane[0].Width - (bw - offset - 23) + margin )+"px"
						: "-"+margin+"px"
					;

					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++;
		}
	}
}