/*********************************************
*
*            Nested Pop-up Menu
*    confirms to: DTD XHTML 1.0 Transitional
*    
*
**********************************************/


/////////////////////////////////////////////////////
//             SCRIPT-WIDE DEFAULTS:			   //

var BASE_URL = "./"; // URL BASE
var BORDER_COLOR = "#FFF"; // border color
var BG_COLOR = "#FED400"; // background color
var HIGHLIGHT = "black"; // highlight color
var HIGHLIGHT_TEXT_COLOR = "#FED400"; // highlight color
var TEXT_COLOR = "black"; // highlight color

var BG_ITEM_MENU = "url(images/menu-arrow.gif)"; // background image for items with menu in them

var TEXT_STYLE = "font-family:Arial;font-weight:bold;font-size:12px;color:"+TEXT_COLOR; // text style
var ITEM_HIGH = 16; // menu item height
var ITEM_WIDTH = 125; // menu item width
var FIRST_MENU_LEFT = 0; // horizontal position of the first menu 
var FIRST_MENU_TOP = 0; // vertical position of the first menu
/////////////////////////////////////////////////////

var rootMenuTimeOut=0;  //reference to a timeout before showing any root menu 
var hideMenuTimeOut=0;  //reference to a timeout before hiding any menu 

var allMenus = new Array();  // array with references to all menus

function MainMenu(menuContentArray){
	// check for unsupported browsers
	if ((navigator.product == "Gecko") || (document.all)){
	    var menus = new Array();  // menus attached 
		var n;	// iteration
		var MAIN_MENU;  

		this.MAIN_MENU = true;  // marks that menus are children of the main menu

		for (var n = 0 ; n < menuContentArray.length; n++){
			menus [n] = new Menu(menuContentArray[n], false, FIRST_MENU_LEFT + (n*ITEM_WIDTH), FIRST_MENU_TOP,this);
		}
		this.menus = menus;
		
	}else{
		//alert("Browser not supported");
	}
}

function Menu(menuContentArray, siblingMenu, leftPos, topPos, parent){  
	var left, top, width; // positions/dimmentions
	var hideTimeout;  // holds ID of setTimeout if menu is to be hidden
	var menuId;   // holds globally accessible ID of this menu (used by setTimeout)
	var parent; // parent menuItem or MainMenu 
	var menuItems = new Array();  // menu items in this menu
	var i;	// iteration
	var menuLayer;
	
	this.hideTimeout = 0;
	this.parent = parent;
	
	if (siblingMenu){
		this.left = siblingMenu.left+siblingMenu.width-2;
		this.top = siblingMenu.top;
	}else{
		this.left = leftPos;
		this.top = topPos;
	}
	
	
	this.width= ITEM_WIDTH;

	
	this.menuId = allMenus.length+1000;
	allMenus[allMenus.length] = this;	
	
	//create menuItems
	for (i = 0 ; i < menuContentArray.length; i ++){
		menuItems[i] = new menuItem(menuContentArray[i], this, (i>0)?(menuItems[i-1]):null);
	}

	//draw menu:
	document.write ('<DIV ID="menu' + this.menuId +'" STYLE="filter:alpha(opacity=90); filter:progid:DXImageTransform.Microsoft.Alpha(opacity=90); -moz-opacity:0.9;position:absolute;BACKGROUND:'+ BORDER_COLOR +';' + 
		';Z-INDEX:'+ this.menuId+';VISIBILITY:HIDDEN;TOP:' + this.top + 'px;LEFT:' + this.left + 'px;overflow:visible;clip:auto;"');
	document.writeln (' onMouseOut="hideMenuTimeOut=setTimeout(\'allMenus[' + this.menuId + '].Hide();\',400)" onMouseOver="clearTimeout(hideMenuTimeOut);">');
		//draw menuItems
		for (i = 0; i < menuItems.length; i ++){
			drawMenuItem(menuItems[i],i);
		}
	//close menu	
	document.write ('</DIV>');
	
	this.menuLayer = document.getElementById('menu' + this.menuId );
	this.menuItems = menuItems;
	
}


function menuItem(itemContentArray, parentMenu, siblingItem){
	var left, top, width, height; // positions/dimmentions
	var itemID, text, link, menu;  // item can have link or menu attached to its text
	var parent;  // parent menu
	var i;	// iteration
	var menuLayer; // graphical representation (menuLayer/Div)
	var SUB_MENU;  
	this.SUB_MENU = true;  // marks that menus are sub-menus of the item

	this.parent= parentMenu;
	
	if (siblingItem){
		this.left = siblingItem.left;
		this.top = siblingItem.top+siblingItem.height;
	}else{  // first item: beginning of parent menu
		this.left = parentMenu.left;
		this.top = parentMenu.top;
	}
	this.width=ITEM_WIDTH;
	this.height=ITEM_HIGH;

	this.text = itemContentArray[0];	// text of the item
	this.itemID = itemContentArray[0] + parentMenu.menuId ;  // generate an ID for the item
	
	
	if (typeof itemContentArray[1] == "string"){ 
		this.link  = itemContentArray[1];  // this item has a link in it
		this.menu = null;
	}else{ 
		this.link  = null;
		this.menu = new Menu (itemContentArray[1], this,null,null,this);  // this item has a sub-menu in it
	}
}

function drawMenuItem(mItem, n){
	document.write ('<DIV ID="' + mItem.itemID +'" STYLE="' + TEXT_STYLE + ';POSITION:RELATIVE;BACKGROUND: ' + BG_COLOR + ' ' +((mItem.menu)?(BG_ITEM_MENU):'') + 
		';VISIBILITY:HIDDEN;MARGIN-TOP:'+ (n==0?1:0) +'px;MARGIN-BOTTOM:1px;MARGIN-LEFT:1px;MARGIN-RIGHT:1px;PADDING-LEFT:2px;PADDING-TOP:0px;WIDTH:' + mItem.width + 'px;overflow:visible;" onMouseOver="this.codeObj.mOver();" onMouseOut="this.codeObj.mOut();" ');
	if (mItem.menu) {
		document.write (' onClick="this.codeObj.mOver();"');
	}else{
		document.write (' onClick="window.location=\'' + BASE_URL + mItem.link +'\'"');
	}
	document.writeln ('>');
	
	document.write (mItem.text);

	document.writeln ('</DIV>');
	
	mItem.menuLayer = document.getElementById(mItem.itemID);
	mItem.menuLayer.codeObj = mItem;
}

function menuItem_mOver(){
	clearTimeout(hideMenuTimeOut); // do not hide
	// if this item is in the sub menu, keep menu of the parent item highlighted
	if (this.parent.parent && this.parent.parent.SUB_MENU){
		this.parent.parent.mOver();
	}

	
	// UNHIGHLIGHT OTHER ITEMS IN THE SAME MENU:
	for (var i = 0; i < this.parent.menuItems.length; i++){
		if (! (this.parent.menuItems[i] == this)) {
			this.parent.menuItems[i].mOut();
		}
	}

	this.menuLayer.style.background = HIGHLIGHT + ' ' + ((this.menu)?BG_ITEM_MENU:'');
	this.menuLayer.style.color = HIGHLIGHT_TEXT_COLOR;
	
	if (this.menu){
		this.menu.Show();
	}
	this.parent.Show();
}

function menuItem_mOut(){
	this.menuLayer.style.background = BG_COLOR + ' ' + ((this.menu)?BG_ITEM_MENU:'') // UN-HIGHLIGHT
	this.menuLayer.style.color = TEXT_COLOR;
	if (this.menu && (this.menu.menuLayer.style.visibility != "HIDDEN")){  // if it has a subMenu and it is not hidden, try to hide it.		
		this.menu.Hide();
	}
}


function Menu_Show(){
	clearTimeout(hideMenuTimeOut); // do not hide
	this.menuLayer.style.visibility = "VISIBLE";
	
	// HIDE OTHER MENUS OF THE MAIN MENU:
	if (this.parent && this.parent.MAIN_MENU){
		for (var k = 0; k < this.parent.menus.length; k++){
			if (! (this.parent.menus[k] == this)) this.parent.menus[k].Hide();
		}
	}

	// SHOW THIS MENU
	for (var ii = 0 ; ii < this.menuItems.length; ii ++){
		this.menuItems[ii].menuLayer.style.visibility = "VISIBLE";
		this.menuItems[ii].menuLayer.style.cursor = "hand"; // CURSOR = hand / pointer 
	}

}

function Menu_Hide(){
	this.menuLayer.style.visibility = "HIDDEN";
	for (var d=0; d<this.menuItems.length; d ++){ // hide items
		this.menuItems[d].menuLayer.style.visibility = "HIDDEN"
		this.menuItems[d].mOut();
	}
	clearTimeout(hideMenuTimeOut);
//	if (this.parent.parent){hideMenuTimeOut=setTimeout('allMenus[' + this.parent.parent.menuId + '].Hide2();',1000)}
}

function Menu_Hide2(){
	this.menuLayer.style.visibility = "HIDDEN";
	for (var d=0; d<this.menuItems.length; d ++){ // hide items
			this.menuItems[d].menuLayer.style.visibility = "HIDDEN"
	}
	clearTimeout(hideMenuTimeOut);
	if (this.parent.parent){hideMenuTimeOut=setTimeout('allMenus[' + this.parent.parent.menuId + '].Hide2();',1000)}
}


menuItem.prototype.mOver= menuItem_mOver;
menuItem.prototype.mOut= menuItem_mOut;

Menu.prototype.Show= Menu_Show;
Menu.prototype.Hide= Menu_Hide;
Menu.prototype.Hide2= Menu_Hide2;

var dashMenu = new MainMenu([
									[/*Home*/
									    ["",""]
									],
									[ /*Services*/
										["Same Day Courier","services.html"],
										["Medical Courier","medical.html"],
										["Legal Courier","legal.html"],
										["Cargo Courier","cargo.html"],
										["Out Of Town Services","outoftown.html"],
										["Warehousing","warehousing.html"]
										
									],
									[/*New Customers*/
										["Request Rates","newcust.asp"],
										["Open New Account","newcust.asp"]
										
									],
									[/*Locations*/
										["Charlotte", "charlotte_courier.html"],
										["Raleigh", "raleigh_courier.html"],
									    ["Greensboro", "greensboro_courier.html"],
									    ["North Carolina Regions", [
												                    ["Western NC", "western_nc_courier.html"],
												                    ["Piedmont", "piedmont_nc_courier.html"],
												                    ["Coastal NC", "coastal_nc_courier.html"]
												                   ]
															],
									    ["South Carolina Regions", [
												                    ["Western SC", "western_sc_courier.html"],
												                    ["Piedmont", "piedmont_sc_courier.html"],
												                    ["Coastal SC", "coastal_sc_courier.html"]
												                   ]
															]									
									],
									[/*For Drivers*/
										["For Drivers", "drivers.shtml"]									
									],
									[/*Order Online*/
										["<DIV ID='loginMenu'><FORM method='POST' action='http://order.dashcourier.com:81/wo/weborder/j_security_check'><CENTER>ONLINE ORDERING</CENTER>User Name<BR><INPUT CLASS='textInput' TYPE='text' NAME='j_username' ID='j_username'/><BR>Password<BR><INPUT CLASS='textInput' TYPE='password' NAME='j_password'/><BR><INPUT width=62 height=15 TYPE=image src='images/login.gif' CLASS='ImageInput'/><input type='hidden' name='j_uri' value='/weborder/OrderList.jsp'/></FORM><CENTER><A HREF='newcust.asp'>REQUEST ACCESS</A></CENTER></DIV>",".."+location.pathname+"#"]
										
									]
							
								]); 



