
ie=false
ns=false

if (document.all)
{
	ie=true;
}
if (document.layers)
{
	ns=true;
}
if (window.navigator.platform.substr(0,3) == "Mac")
{
	ie=false;
	ns=false;
}
arrMenus=new Array();

function menuhideall()
{
// Hides all menus
	for (i in arrMenus)
	{
		if (ie)
		{
			document.all[arrMenus[i]].style.visibility='hidden';
		}
		if (ns)
		{
			document.layers[arrMenus[i]].visibility='hidden';
		}
	}
}

/*function menumovehandler()
{
//	menuhideall();
}*/
function menuoverhandler()
{
	if (ie)
	{
		if (event.srcElement.tagName=="TD")
		{
	// Set everything to menuitem
			oParent=event.srcElement.parentElement.parentElement
/*			for (oChild in oParent.children)
			{
				alert(oParent.children[oChild].tagName)
			}*/
			menuturnoff(oParent)
			event.srcElement.className="menuhighlight"
			for (oChild in event.srcElement.children)
			{
				event.srcElement.children[oChild].className="menuhighlight"
			}
		}
	}
}

function menuturnoff(oElement)
{
	if (oElement.className="menuhighlight")
	{
		oElement.className="menuitem"
	}
	for (oChild in oElement.children)
	{
		menuturnoff(oElement.children[oChild])
	}
}

function menuouthandler()
{
	if (ie)
	{
		if (event.srcElement.tagName=="TD" && event.toElement.tagName != "A")
		{
//			alert(event.srcElement.tagName + " -> " + event.toElement.tagName )
			event.srcElement.className="menuitem"
			for (oChild in event.srcElement.children)
			{
				event.srcElement.children[oChild].className="menuitem"
			}
		}
	}
}

function menuclickhandler()
{
	if (ie)
	{
		if (event.srcElement.tagName=="TD")
		{
// Loop through the cell contents and find the first A tag
			sStr=""
			for (iChild in event.srcElement.children)
			{
				if (event.srcElement.children[iChild].tagName=="A")
				{
					sStr=event.srcElement.children[iChild].href
					break;
				}
			}
			document.location=sStr;
		}
	}
}

/* Mouse Event handler (for closing menus) */
if (document.captureEvents)
{
	document.captureEvents(Event.MOUSEUP)
}

document.onmouseup=menuhideall;

//document.onmousemove=menumovehandler;

window.onresize=menuhideall;
/* ------ Menu Object ------ */

function showId()
{
	alert(this.divId)
}

/* Show Function */
function showMenu(oTarget,above)
{
/*
	showMenu: Displays the menu on the page. 
	Params:		oTarget: Tag to look at in order to determine location. Must be an A tag for NS.
				  above: If true, this renders the menu *above* the oTarget rather than below it. 
	Notes:
		- In IE, there must be a 'LocMain' ID set on the root table of the page to allow for 
		  proper positioning. 
*/
	for (i in arrMenus)
	{
		if (arrMenus[i] == this.divId)
		{
			if (ie)
			{
				var oCurrentNode=document.all[oTarget];
				var yPos=0;
				var xPos=0;
				while(oCurrentNode.tagName!="BODY")
				{
					yPos+=oCurrentNode.offsetTop;
					xPos+=oCurrentNode.offsetLeft;
					oCurrentNode=oCurrentNode.offsetParent;
				}
				if (above)
				{
					yPos=yPos - document.all[arrMenus[i]].offsetHeight;
				}
				else
				{
					yPos=yPos + document.all[oTarget].offsetHeight
				}
				document.all[arrMenus[i]].style.top=yPos;
//				document.all[arrMenus[i]].style.left=document.all[oTarget].parentElement.offsetLeft + document.all['LocMain'].parentElement.offsetLeft;
				document.all[arrMenus[i]].style.left=xPos;
				document.all[arrMenus[i]].style.visibility='visible';
			}
			if (ns)
			{

				if (above)
				{
					yOffset=0 - document.layers[arrMenus[i]].clip.height;
				}
				else
				{
					yOffset=26;
				}
				document.layers[arrMenus[i]].left=document.anchors[oTarget].x;
				document.layers[arrMenus[i]].top=document.anchors[oTarget].y + yOffset;
				document.layers[arrMenus[i]].visibility='visible';
			}
		}
		else
		{
			if (ie)
			{
				document.all[arrMenus[i]].style.visibility='hidden';
			}
			if (ns)
			{
				document.layers[arrMenus[i]].visibility='hidden';
			}
		}
	}
}

/* Constructor */
function JMnu(sDivId)
{
	this.divId = sDivId
	this.showId = showId
	this.showMenu = showMenu
	arrMenus[arrMenus.length + 1] = sDivId
}