/**
@private
*/
function openWin(URL)
	{ 

	newWindow = window.open (URL,"_tabuevent","width=420,height=220,scrollbars=no,resizable=no");
	newWindow.focus();
	}
function getAbsX(elt)
{
    return (elt.x) ? elt.x : getAbsPos(elt,"Left");
}

/**
@private
*/
function getAbsY(elt)
{
   // alert (getLevels(elt));
    return (elt.y) ? elt.y : getAbsPos(elt,"Top");
}

/**
@private
*/
function getAbsPos(elt,which)
{
    var iPos = 0;
    while (elt != null)
    {
        //alert (elt["offset" + which]);
        iPos += elt["offset" + which];
        elt = elt.offsetParent;
    }
    return iPos;
}

function highlightMenuBar(theObj)
{
	theObj.className = "selectedMenu";
}

function OpenMenuBar(theObj)
{
	highlightMenuBar(theObj);
}

//===============================OBJECTS

var menuBars = new Array();
function MenuBar(id)
{
	this.id = id;	
	this.menus = new Array();
	this.add = function(menu)
	{
		menu.id = this.id + "_menu_" + this.menus.length;
		this.menus[this.menus.length] = menu;
	}
	this.toString = menuBarToString_function;
	//this.showMenu = showMenu_function;
	menuBars[id] = this;
}

function getMenuBar(id)
{
	return menuBars[id];
}

function menuBarToString_function()
{
	var buffer = "";
	buffer += "<table border='0' cellspacing='0' cellpadding='0'><tr>";
	buffer+= "<td onmouseover='clearAllTimers()'>";
	for (var i=0; i < this.menus.length; i++)
	{
		buffer += "<a href='"+ this.menus[i].action +"' id='" + this.menus[i].id + "' class='menu' onmouseout='closeMenu()' onmouseover='showMenu_helper(this)'>" + this.menus[i].text + "</a>";
	}
	buffer+= "</td>";
	buffer+= "</tr>";
	buffer+= "</table>";
	buffer += "<div id='" + this.id + "_dropDownMenu' class='dropDownMenu'></div>";
	return buffer;
}

function highlightMenuItem_helper(theObj)
{
	var menuBarId = theObj.id.split("_")[0];
	var menuId = theObj.id.split("_")[2];
	for (var i=0; i< getMenuBar(menuBarId).menus.length; i++)
	{
		if (i == menuId)
		{
			getMenuBar(menuBarId).menus[i].highlight();
		}
		else
		{
			getMenuBar(menuBarId).menus[i].unhighlight();
		}
	}
	theObj.className = "menuItemSelected";
}

function unhighlightMenuItem_helper(theObj)
{
	theObj.className = "menuItem";
}

function showMenu_helper(theObj)
{
	//theObj.id:tot_menu_1;
	var menuBarId = theObj.id.split("_")[0];
	var menuId = theObj.id.split("_")[2];
	for (var i=0; i< getMenuBar(menuBarId).menus.length; i++)
	{
		if (i == menuId)
		{
			getMenuBar(menuBarId).menus[i].highlight();
			getMenuBar(menuBarId).menus[i].show();
		}
		else
		{
			getMenuBar(menuBarId).menus[i].unhighlight();
			//getMenuBar(menuBarId).menus[i].hide();
		}
	}
}

function Menu(text,action,target)
{
	this.id = null;
	this.text = text;	
	this.action = action;
	this.target = target;
	this.menuItems = new Array();
	this.add = function (menuItem)
	{
		menuItem.id = this.id + "_menuitem_" + this.menuItems.length;
		this.menuItems[this.menuItems.length] = menuItem;
	}
	this.highlight = highlight_function;
	this.unhighlight = unhighlight_function;
	this.show = menushow_function;
	this.hide = menuhide_function;
}

function highlight_function()
{
	document.getElementById(this.id).className = "selectedMenu";
}

function unhighlight_function()
{
	document.getElementById(this.id).className = "menu";
}

function menushow_function ()
{
	
	if (this.menuItems.length <= 0)
	{
		reset();
		return;
	}
	var buffer ="";
	for (var i=0; i < this.menuItems.length; i++)
	{
		buffer += "<a href='"+ this.menuItems[i].action +"'style='display:block;text-decoration:none;' onmouseout='unhighlightMenuItem_helper(this)' onmouseover='highlightMenuItem_helper(this);clearAllTimers()' id='" + this.id + "_menuitem_" + i + "' class='menuItem'>" + this.menuItems[i].text + "</a>";
	}
	var menuId = this.id.split("_")[0];
	
	document.getElementById(menuId + "_dropDownMenu").innerHTML = buffer;
	document.getElementById(menuId + "_dropDownMenu").style.display = "block";
	document.getElementById(menuId + "_dropDownMenu").style.position = "absolute"
	
	if (this.id.indexOf("4")!= -1)
	{	//Services Menu
		document.getElementById(menuId + "_dropDownMenu").style.width = "180px";
		document.getElementById(menuId + "_dropDownMenu").style.left  = (getAbsX(document.getElementById(this.id))  )+ "px";
	}
	else
	if (this.id.indexOf("2")!= -1)
	{	//About Us Menu
		document.getElementById(menuId + "_dropDownMenu").style.width = "165px";
		document.getElementById(menuId + "_dropDownMenu").style.left  = (getAbsX(document.getElementById(this.id))  )+ "px";
	}
	else
	if (this.id.indexOf("3")!= -1)
	{	//Buy Menu
		document.getElementById(menuId + "_dropDownMenu").style.width = "120px";
		document.getElementById(menuId + "_dropDownMenu").style.left  = (getAbsX(document.getElementById(this.id))  )+ "px";
	}
	else
	if (this.id.indexOf("5")!= -1)
	{	//Facilities Menu
		document.getElementById(menuId + "_dropDownMenu").style.width = "160px";
		document.getElementById(menuId + "_dropDownMenu").style.left  = (getAbsX(document.getElementById(this.id))  )+ "px";
	}
	else
	if (this.id.indexOf("6")!= -1)
	{	//Contact Us Menu
		document.getElementById(menuId + "_dropDownMenu").style.width = "144px";
		//document.getElementById(menuId + "_dropDownMenu").style.left  = "640px";
		
		document.getElementById(menuId + "_dropDownMenu").style.left  = (getAbsX(document.getElementById(this.id))  )+ "px";
	}
	else
	{
		document.getElementById(menuId + "_dropDownMenu").style.width = "150px";			
		document.getElementById(menuId + "_dropDownMenu").style.left  = (getAbsX(document.getElementById(this.id))  )+ "px";
	}
	
	document.getElementById(menuId + "_dropDownMenu").style.top  = (getAbsY(document.getElementById(this.id)) + document.getElementById(this.id).offsetHeight)+ "px";
	if (document.all)
	{
		document.getElementById(menuId + "_dropDownMenu").attachEvent("onmouseout", closeMenu);
	}
	else 
	{
		document.getElementById(menuId + "_dropDownMenu").addEventListener("mouseout", closeMenu,   true);
	}
	if (document.all)
	{
		document.attachEvent("onclick", reset);
	}
	else 
	{
		document.addEventListener("click", reset,   true);
	}
}

var temp = 0;
function clearAllTimers()
{
	window.clearTimeout (temp);	
}

function closeMenu()
{
	window.clearTimeout (temp);
	temp = window.setTimeout("reset()","1000");
}

function reset()
{
	document.getElementById("tot" + "_dropDownMenu").style.display = "none";
	for (var i=0; i< getMenuBar("tot").menus.length; i++)
	{
		getMenuBar("tot").menus[i].unhighlight();
	}
	if (document.all)
	{
		document.detachEvent("onclick", closeMenu);
	}
	else 
	{
		document.removeEventListener("click", closeMenu,   true);
	}
}

function menuhide_function ()
{
	var menuId = this.id.split("_")[0];
	document.getElementById(menuId + "_dropDownMenu").style.display = "none";
}

function MenuItem (text,action)
{
	this.id = null;
	this.text = text;
	this.action = action;
	this.menuId = null;
	this.menuItems = new Array();
	this.add = function (menuItem)
	{
		menuItem.id = this.id;
		this.menuItems[this.menuItems.length] = menuItem;
	}
}

function UnhighlightMenuBar(theObj)
{
	theObj.className = "menu";
}
