function Rect (intLeft, intTop, intRight, intBottom)
{
	this.Left = intLeft;
	this.Top = intTop;
	this.Right = intRight;
	this.Bottom = intBottom;
}

function Menu(strName, Div, strForeColor, strBackColor, strHighlightForeColor, strHighlightBackColor)
{
	this.Name = strName;
	this.arrItems = new Array();
	this.Div = Div;
	this.ForeColor = strForeColor;
	this.BackColor = strBackColor;
	this.HighlightForeColor = strHighlightForeColor;
	this.HighlightBackColor = strHighlightBackColor;
	this.Bounds = new Rect(0, 0, 0, 0);
	this.CurrentItem = null;
	this.Show = Menu_Show;
	this.Hide = Menu_Hide;
	this.AddItem = Menu_AddItem;
	this.SetBounds = Menu_SetBounds;
	this.BoundsHitTest = Menu_BoundsHitTest;
	this.SetBounds();
}

function Menu_Show()
{
	this.Div.style.visibility = "visible";
}

function Menu_AddItem(objItem)
{
	objItem.ParentMenu = this;
	this.arrItems[this.arrItems.length] = objItem;
}

function Menu_SetBounds()
{
	this.Bounds = new Rect(this.Div.style.pixelLeft, this.Div.style.pixelTop, this.Div.style.pixelLeft + this.Div.clientWidth, this.Div.style.pixelTop + this.Div.clientHeight);
}

function Menu_BoundsHitTest(intX, intY)
{
	var blnResult = false;
	if ((intX >= this.Bounds.Left) && (intX <= this.Bounds.Right) && (intY >= this.Bounds.Top) && (intY <= this.Bounds.Bottom))
	{
		blnResult = true;
	}
	return blnResult;
}

function Item(strName, Div, objSubMenu, strURL)
{
	this.Name = strName;
	this.Div = Div;
	this.Div.Item = this;
	this.ParentMenu = null;
	this.SubMenu = objSubMenu;
	this.URL = strURL;
	this.HighlightItem = true;
	this.Focus = Item_Focus;
	this.Blur = Item_Blur;
	this.Div.onmouseover = DivOnMouseOver;
	this.OnMouseOver = Item_OnMouseOver;
	this.Div.onmouseout = DivOnMouseOut;
	this.OnMouseOut = Item_OnMouseOut;
	this.Div.onclick = DivOnClick;
	this.OnClick = Item_OnClick;
}

function Item_Focus()
{
	if (this.ParentMenu.CurrentItem)
	{
		this.ParentMenu.CurrentItem.Blur();
		if (this.ParentMenu.CurrentItem.SubMenu)
		{
			this.ParentMenu.CurrentItem.SubMenu.Hide();
		}
	}
	this.ParentMenu.CurrentItem = this;
	if (this.HighlightItem)
	{
		this.Div.style.color = this.ParentMenu.HighlightForeColor;
		this.Div.style.backgroundColor = this.ParentMenu.HighlightBackColor;
	}
	if (this.SubMenu)
	{
		this.SubMenu.Show();
	}
}

function Item_Blur()
{
	if (this.HighlightItem)
	{
		this.Div.style.backgroundColor = this.ParentMenu.BackColor;
		this.Div.style.color = this.ParentMenu.ForeColor;
	}
}

function Item_OnMouseOver()
{
	changetext(content[this.URL]);
	changestatus(stattext[this.URL]);
	this.Focus();
}

function DivOnMouseOver()
{
	this.Item.OnMouseOver();
}

function Item_OnMouseOut()
{
}

function DivOnMouseOut()
{
	changetext(content[0]);
	changestatus(stattext[0]);
	this.Item.OnMouseOut();
}

function Menu_Hide()
{
	if (this.CurrentItem)
	{
		if (this.CurrentItem.SubMenu)
			this.CurrentItem.SubMenu.Hide();
		this.CurrentItem.Blur();
		this.CurrentItem = null;
	}
	this.Div.style.visibility = "hidden";
}

function Item_OnClick()
{
	changetext(content[0]);
	if (this.URL)
	{
		if (this.URL.length > 2){
			this.ParentMenu.Hide();
		}
		if (this.URL != '@'){
			Action(this.URL);
			
		}
	}
}

function DivOnClick()
{
	this.Item.OnClick();
}

function CheckMouseOverMenu()
{
	var blnResult = false;
	var blnDone = false;
	var intX = window.event.clientX + document.body.scrollLeft;
	var intY = window.event.clientY + document.body.scrollTop;
	var mnuTemp = mnuMain;
	
	blnResult = mnuTemp.BoundsHitTest(intX, intY);
	while ((!blnResult) && (!blnDone))
	{
		if (mnuTemp.CurrentItem)
		{
			if (mnuTemp.CurrentItem.SubMenu)
			{
				mnuTemp = mnuTemp.CurrentItem.SubMenu;
				blnResult = mnuTemp.BoundsHitTest(intX, intY);
			}
			else
			{
				blnDone = true;
			}
		}
		else
		{
			blnDone = true;
		}
	}
	if (!blnResult)
	{
		if (mnuMain.CurrentItem)
		{
			if (mnuMain.CurrentItem.SubMenu)
			{
				mnuMain.CurrentItem.SubMenu.Hide();
			}
			mnuMain.CurrentItem.Blur();
		}
	}
}