// JavaScript Document

function SetMenuAwareness()
{
	if( document.getElementById("main-nav") === null ){ return; }
	
	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.
	//# 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] = 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"; }
				
				if (window.attachEvent){ this.className=this.className.replace("sfhover", ""); }
			}
			
			x++;
		}
	}
}


/*
function initMenu()
{
	var nodes = document.getElementById("main-nav").getElementsByTagName("strong");
	for (var i=0; i<nodes.length; i++)
	{
		nodes[i].onmouseover = function()
		{
			this.className += " hover";
		}
		nodes[i].onmouseout = function()
		{
			this.className = this.className.replace(" hover", "");
		}
	}
}
if (document.all && !window.opera) attachEvent("onload", initMenu);



var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#main-nav > li').bind('mouseover', jsddm_open);
	$('#main-nav > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;

*/

$(document).ready(function(){ SetMenuAwareness(); });
