var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 



// EVENHEIGHTS FUNCTION

function evenheights()
{
	sidebar = document.getElementById('sidebardiv');	
	main = document.getElementById('maindiv');
	
	if (navigator.appName.indexOf("Microsoft") >= 0)
	{
		heightsidebar = sidebar.getAttribute('offsetHeight');
		heightmain = main.getAttribute('offsetHeight');
		
	}
	else
	{
		heightsidebar = document.defaultView.getComputedStyle(sidebar,"").getPropertyValue("height");
		heightmain = document.defaultView.getComputedStyle(main,"").getPropertyValue("height");
		
		heightmain = heightmain.replace("px","");
		heightmain = parseInt(heightmain) + 10;
		heightmain = heightmain + "px";
	}
	
	if (parseInt(heightsidebar) < parseInt(heightmain))
	{
		sidebar.style.height = heightmain;
	}
}

// END of EVENHEIGHTS FUNCTION

function getRef(id) 
{
	return document.getElementById(id);
}

function getSty(id)
{
	return getRef(id).style;
}

// Hide timeout
var PopTimer = 0;

// Array showing highlighted menu items.
var HighlightedTitles = new Array();


//////////////////////////////////////////////////
//                                              //
//  PopOver Function                            //
//                                              //
//////////////////////////////////////////////////

function popOver(menuNum, itemNum) 
{
	// Clear the Last PopOut Timer
	clearTimeout(PopTimer);
	
	// Hide All Menus Besides This Menu
	HideAllMenusBesides(menuNum);
	
	// Find the Path of All Menu Items that Should Be Highlighted
	HighlightedTitles = GetPathToRoot(menuNum, itemNum);
	
	// Change the Color of All Appropriate Menu Items
	ChangeColor(HighlightedTitles, true);
	
	// Find the Target Menu of This Menu Item
	TargetNum = menu[menuNum][itemNum].target;
	
	if (TargetNum > 0) 
	{
		thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
		thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
		
		with (menu[TargetNum][0].ref) 
		{
			left = parseInt(thisX + menu[TargetNum][0].x) +"px";
			top = parseInt(thisY + menu[TargetNum][0].y) +"px";
			visibility = 'visible';
      		}
   	}
}


//////////////////////////////////////////////////
//                                              //
//  PopOut Function                             //
//                                              //
//////////////////////////////////////////////////

function popOut(menuNum, itemNum) 
{
	// If This is a Header Label With No Target Menu....
	if ((menuNum == 0) && !menu[menuNum][itemNum].target)
	{
		// Hide All Submenus Immediately
		HideAllMenusBesides(0);
	}
	else
	{
		// Hide All Submenus After a Time Delay
		PopTimer = setTimeout('HideAllMenusBesides(0)', 100);
	}
}



//////////////////////////////////////////////////
//                                              //
//  GetTree Function                            //
//                                              //
//////////////////////////////////////////////////

function GetPathToRoot(menuNum, itemNum) 
{
	// Array index is the menu number. The contents are null (if that menu is not a parent)
	// or the item number in that menu that is an ancestor (to light it up).
	
	itemArray = new Array(menu.length);

	while(1) 
	{
		itemArray[menuNum] = itemNum;

		// If we've reached the top of the hierarchy, return.
		if (menuNum == 0)
		{
			return itemArray;
		}
		
		itemNum = menu[menuNum][0].parentItem;
		menuNum = menu[menuNum][0].parentMenu;
   	}
}


//////////////////////////////////////////////////
//                                              //
//  ChangeColor Function                        //
//                                              //
//////////////////////////////////////////////////

// Pass an array and a boolean to specify color change, true = over color.
function ChangeColor(ChangeArray, isOver) 
{
	for (menuCount = 0; menuCount < ChangeArray.length; menuCount++) 
	{	
		if (ChangeArray[menuCount]) 
		{
			NewColor = isOver ? menu[menuCount][0].OverColor : menu[menuCount][0].BackColor;

			// Change the colors of the div background

			with (menu[menuCount][ChangeArray[menuCount]].ref)
			{
				backgroundColor = NewColor;	
         		}
      		}	
   	}
}


//////////////////////////////////////////////////
//                                              //
//  HideAllMenusBesides Function                //
//                                              //
//////////////////////////////////////////////////

function HideAllMenusBesides(menuNum)
{
	var keepMenus = GetPathToRoot(menuNum, 1);
	
	for (count = 0; count < menu.length; count++)
	{
		if (!keepMenus[count])
		{
			menu[count][0].ref.visibility = 'hidden';
			ChangeColor(HighlightedTitles, false);
		}
	}	
}



//////////////////////////////////////////////////
//                                              //
//  Menu Constructor                            //
//                                              //
//////////////////////////////////////////////////

function Menu(isVert, popInd, x, y, width, OverColor, BackColor, borderClass, textClass)
{
	// Vertical Menu or Not
	this.isVert = isVert;
	
	// PopUp Indicator
	this.popInd = popInd
	
	// Position and Size Settings
	this.x = x;
	this.y = y;
	this.width = width;

	// Color of Menu and Items
	this.OverColor = OverColor;
	this.BackColor = BackColor;

	// Stylesheet for Item Borders and Item Text
	this.borderClass = borderClass;
	this.textClass = textClass;

	// Parent Menu and Parent Item
	this.parentMenu = null;
	this.parentItem = null;

	// Reference to the Objects Style 
	this.ref = null;
}



//////////////////////////////////////////////////
//                                              //
//  Item Constructor                            //
//                                              //
//////////////////////////////////////////////////

function Item(text, href, frame, length, spacing, target)
{
	this.text = text;
	this.href = href;
	this.frame = frame;
	this.length = length;
	this.spacing = spacing;
	this.target = target;

	// Reference to the Objects Style Properties
	this.ref = null;
}




//////////////////////////////////////////////////
//                                              //
//  WriteMenus Function                         //
//                                              //
//////////////////////////////////////////////////

function writeMenus() 
{

	return;

	for (CurrentMenu = 0; CurrentMenu < menu.length; CurrentMenu++) with (menu[CurrentMenu][0])
	{
	
		var str = '';
		var itemX = 0;
		var itemY = 0;

	
		for (CurrentItem = 1; CurrentItem < menu[CurrentMenu].length; CurrentItem++) with (menu[CurrentMenu][CurrentItem])
		{
			var itemID = 'menu' + CurrentMenu + 'item' + CurrentItem;

			var w = (isVert ? width : length);
			var h = (isVert ? length : width);

			str += '<div id="' + itemID + '" style="margin: 0px; padding: 0px; position: absolute; left:' + itemX + 'px; top: ' + itemY + 'px; width: ' + w + 'px; height: ' + h + 'px; visibility: inherit; ';
			

			if (BackColor)
			{
				str += 'background-color: ' + BackColor + '; ';
			}
	
			str += '" ';

			if ((CurrentMenu != 0) || (CurrentItem !=1))
			{
				if (borderClass) 
				{
					str += 'class="' + borderClass + '" ';
				}
			}
	
			// Add mouseover handlers and finish DIV
			str += 'onMouseOver="popOver(' + CurrentMenu + ',' + CurrentItem + ')" onMouseOut="popOut(' + CurrentMenu + ',' + CurrentItem + ')">';

			// Add contents of item 
			str += '<a class="' + textClass + '" style="display: block; float: left; padding-left: 10px; margin-top: 3px;" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') + text + '</a>';
		
			if (target > 0)
			{

				// Set target's parents to this menu item.
				menu[target][0].parentMenu = CurrentMenu;
				menu[target][0].parentItem = CurrentItem;

				// Add a popout indicator.
				if (popInd)
				{
					str += '<a class="' + textClass + '" style="display: block; float: left; padding-left: 5px; margin-top: 3px;">' + popInd + '</a>';
				}
			}
		
			str += '</div>';

			if (isVert)
			{
				itemY += length + spacing;
			}
			else 
			{
				itemX += length + spacing;
			}
		}
	

		var newDiv = document.createElement('div');
		document.getElementsByTagName('body').item(0).appendChild(newDiv);
		//document.getElementById('headerdiv').appendChild(newDiv);
		
		ref = newDiv.style;
		ref.position = 'absolute';
		ref.visibility = 'hidden';
		newDiv.innerHTML = str;


		for (CurrentItem = 1; CurrentItem < menu[CurrentMenu].length; CurrentItem++) 
		{
			itemName = 'menu' + CurrentMenu + 'item' + CurrentItem;
			menu[CurrentMenu][CurrentItem].ref = getSty(itemName);

   		}


	menu[CurrentMenu][0].ref.left = menu[CurrentMenu][0].x + "px";
	menu[CurrentMenu][0].ref.top = menu[CurrentMenu][0].y + "px";

	}

	menu[0][0].ref.visibility = 'visible';

	document.write("<div></div>");

}


var menu = new Array();

var defOver = '#669999';
var defBack = '#7373EE';

// Default 'length' of menu items - item height if menu is vertical, width if horizontal
var defLength = 23;

// Menu 0 is the special, 'root' menu from which everything else arises
menu[0] = new Array();
menu[0][0] = new Menu(false, '', 16, 112, 21, '#669999', '#7373EE', 'menuclass', 'itemText');
menu[0][1] = new Item('Home', '../index.html', '', 50, 0, 0);
menu[0][2] = new Item('Login', '../loginchoosetype.php', '', 50, 0, 1);
menu[0][3] = new Item('Products', '../productdirectory.html', '', 75, 0, 0);
menu[0][4] = new Item('Linecard', '../linecard.html', '', 80, 0, 0);
menu[0][5] = new Item('Upcoming Events', '../upcomingevents.html', '', 115, 0, 0);
menu[0][6] = new Item('Jobs', '../jobopenings.html', '', 55, 0, 0);
menu[0][7] = new Item('News', '../pressreleasedirectory.html', '', 55, 0, 0);
menu[0][8] = new Item('Staff', '../staff.html', '', 60, 0, 0);
menu[0][9] = new Item('About', '../aboutus.html', '', 100, 0, 0);

// LOGIN MENU
menu[1] = new Array();
menu[1][0] = new Menu(true, '>', 0, 25, 125, defOver, defBack, 'menuclass', 'itemText');
menu[1][1] = new Item('Customers', '../users/index.php', '', defLength, 0, 0);
menu[1][2] = new Item('Vendors', '../users/index.php', '', defLength, 0, 0);
menu[1][3] = new Item('Employees', '../staff/index.php', '', defLength, 0, 0);


// PROVIDER DIRECTORY MENU
menu[2] = new Array();
menu[2][0] = new Menu(true, '>', 0, 25, 125, defOver, defBack, 'menuclass', 'itemText');
menu[2][1] = new Item('About Axis', '../aboutaxis.html', '', defLength, 0, 0);
menu[2][2] = new Item('Staff', '../staff.html', '', defLength, 0, 0);


// PRODUCTS & SYSTEMS MENU
menu[3] = new Array();
menu[3][0] = new Menu(true, '>', 0, 25, 125, defOver, defBack, 'menuclass', 'itemText');
menu[3][1] = new Item('Automation Products', '../productdirectory.html', '', defLength, 0, 0);
menu[3][2] = new Item('Automation Systems', '../systemdirectory.html', '', defLength, 0, 0);