// JavaScript Document

var _body = document.getElementsByTagName("BODY")[0];
_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.
var oMenuItem = new Array();
var x = 0;
for( var i = 0; i < oLi.length; i++ )
{
	if( parseInt(oLi[i].getAttribute("level")) == 0 )
	{

		oMenuItem[x] = new Object();
		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];
				
				if( (this.Pane[0].Width + offset) >= bw )
				{
					this.Pane[0].style.marginLeft = "-"+( this.Pane[0].Width - (bw - offset - 5) )+"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"; }
			this.className=this.className.replace("sfhover", "");
		}
		
		x++;
	}
}

