
//Rect Object
function Rect (intLeft, intTop, intRight, intBottom)
{
	this.Left = intLeft;
	this.Top = intTop;
	this.Right = intRight;
	this.Bottom = intBottom;
}

//Menu Object
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);
	//alert(this.Name + " " + this.Bounds.Left + ":" + this.Bounds.Top + ":" + this.Bounds.Right + ":" + this.Bounds.Bottom);
	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();
	
	//alert(this.Name + " " + this.Bounds.Left + ":" + this.Bounds.Top + ":" + this.Bounds.Right + ":" + this.Bounds.Bottom);
}

function Menu_Show()
{
	//alert(this.Name);
	this.Div.style.visibility = "visible";
}

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 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 + 20, this.Div.style.pixelTop + this.Div.clientHeight + 20);
}

function Menu_BoundsHitTest(intX, intY)
{
	var blnResult = false;
	//alert (intX + ":" + intY + " " + this.Bounds.Left + ":" + this.Bounds.Top + ":" + this.Bounds.Right + ":" + this.Bounds.Bottom);
	if ((intX >= this.Bounds.Left) && (intX <= this.Bounds.Right) && (intY >= this.Bounds.Top) && (intY <= this.Bounds.Bottom))
	{
		blnResult = true;
	}
	return blnResult;
}

//Item Object
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()
{
	this.Focus();
}

function DivOnMouseOver()
{
	//divMouse.innerText = this.Item.Name;
	this.Item.OnMouseOver();
}

function Item_OnMouseOut()
{
}

function DivOnMouseOut()
{
	this.Item.OnMouseOut();
}

function Item_OnClick()
{
	if (this.URL)
	{
		window.open(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;
	
	//divMouse.innerHTML = intX + "," + intY
	
	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();
		}
	}
}



function PositionMenus()
{
	var WindowWidth  = document.body.clientWidth;
	var MenuTop = 125;
	var PageLeft = -200;
	
	if (WindowWidth > 700)
	{
		PageLeft = (WindowWidth/2) - 390;
	}

	divMainMenu.style.left = PageLeft + 175;
	divMainMenu.style.top = MenuTop;
	divApplyingMenu.style.left = divMainMenu.style.pixelLeft + 405;
	divApplyingMenu.style.top = divMainMenu.style.pixelTop+5;
	
	divProgramsMenu.style.left = divMainMenu.style.pixelLeft + 160;
	divProgramsMenu.style.top = divMainMenu.style.pixelTop + 53;
	
	
	
	if (mnuMain)
	{
		mnuMain.SetBounds();
		mnuApplying.SetBounds();
		mnuPrograms.SetBounds();
		
	}
}
