var g_MenuArray = new Array();
var g_bResized;
function stiMenu(oAnchor)
{
	// assumes that oAnchor is an element Object
	var oTable;
	for (var x = 0; x < oAnchor.childNodes.length; x++)
		if (oAnchor.childNodes[x].tagName)
		{
			oTable = oAnchor.childNodes[x];
			break;
		}
	oAnchor.Menu = oTable;
	if (oAnchor.Menu)
	{
		registerEvent(oAnchor, "onclick", e_stiMenu_onClick);
		registerEvent(document.body, "onclick", e_stiMenu_body_onClick);
		registerEvent(document.body, "onresize", e_stiMenu_body_onResize);
	}
	return oAnchor;
}
function e_stiMenu_onClick(e)
{
	if (!e) e = window.event;
	if (!e.srcElement) e.srcElement = e.target;
	var oAnchor = e.srcElement;
	if (oAnchor.Menu)
	{
		var oMenu = oAnchor.Menu;
		g_MenuArray[g_MenuArray.length] = oMenu;
		var oMenuStyle = oMenu.style;
		oMenuStyle.display = "block";
		if (g_bResized || !oMenuStyle.left)
		{
			oMenuStyle.left = absLeft(oAnchor);
			if ((parseInt(oMenuStyle.left) + oMenu.offsetWidth) > document.body.offsetWidth)
				alert("move the menu!");
			oMenuStyle.top = absTop(oAnchor) + oAnchor.offsetHeight;
			g_bResized = false;
		}
		return false;
	}
}
function e_stiMenu_body_onClick(e)
{
	if (!e) e = window.event;
	if (!e.srcElement) e.srcElement = e.target;
	if (!e.srcElement.Menu)
	{
		for (var x = 0; x < g_MenuArray.length; x++)
		{
			g_MenuArray[x].style.display = "none";
		}
		g_MenuArray.length = 0;
	}
}
function e_stiMenu_body_onResize(e)
{
	g_bResized = true;
}

