/////////////////////////////////////////////////////
//             SCRIPT-WIDE DEFAULTS:			   //

var BASE_URL = "http://www.usground.com/"; // URL BASE
var BORDER_COLOR = "#0000FF"; // border color
var BG_COLOR = "#F8F8F8"; // background color
var HIGHLIGHT = "#00FF00"; // highlight color

var BG_ITEM_MENU = "url(images/menu-arrow.gif)"; // background image for items with menu in them

var TEXT_STYLE = "font-family:Verdana,Arial;color:black;font-weight:bold;font-size:10px"; // text style
var ITEM_HIGH = 15; // menu item height
var ITEM_WIDTH = 145; // menu item width
var FIRST_MENU_LEFT = 20; // horizontal position of the first menu 
var FIRST_MENU_TOP = 111; // 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], null, FIRST_MENU_LEFT + (n*124), 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;
	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 + ';LEFT:' + this.left + '"');
	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 + ';HEIGHT:' + mItem.height + '" 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:'');
	
	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
	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 groundexMenu = new MainMenu([
									[
												["All Services", "servguide.shtml"],

  									["Download  Guide", "USGmulti.pdf"]
	
							
									],
									[
										["Order Courier","order/order.asp"],
										["Manage Inventory","order/myinventory.asp"],
										["Tracking","order/myorders.asp"],
										["Instant Price","order/quotemaker.asp"],
										["New Account Now","credit.shtml"],
										["Get Online Access","order/newacc.asp"],
										["Scheduled Pickup Quote", "routed.shtml"]				
														
										
										
									],
									[
										["About usground","about.shtml"],
										["News","news.shtml"],
										["Locations",[
															["Interactive Map","ma.shtml"],
															["Greater Boston", [
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>617.457.7800</FONT>Boston",	"gb.shtml"]
																			   ]
															],
															["North Shore",		[
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>978.927.0734</FONT>Beverly", "ns.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>978.937.2006</FONT>Lowell",	"ns.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>781.586.0110</FONT>Lynn",	"ns.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>781.321.1800</FONT>Malden",	"ns.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>978.741.0924</FONT>Salem",	"ns.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>781.932.5860</FONT>Woburn",	"ns.shtml"]
																					
																				]
															],
															["South Shore",		[
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>781.848.8811</FONT>Braintree",	"ss.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>508.897.0009</FONT>Brockton",		"ss.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>617.471.4800</FONT>Quincy",		"ss.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>781.407.0518</FONT>Dedham",		"ss.shtml"]
																				]
															],
															["Cape Cod",		[
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>800.698.9800</FONT>Brewster",	"cc.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>800.698.9800</FONT>Sandwich",	"cc.shtml"]
																					
																				]
															],
															["Metro West ",		[
																					["<IMAGE STYLE='float:right;padding-right:4px;width:65;height:7' VSPACE='3' TITLE='508.872.4071' SRC='images/508-872-4071.gif'>Framingham",	"mw.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>508.460.2089</FONT>Marlboro",	"mw.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>508.655.1291</FONT>Natick",		"mw.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>617.928.0050</FONT>Newton",		"mw.shtml"],
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>781.642.9500</FONT>Waltham",		"mw.shtml"]
																				]
															],
															["Central Mass ",	[
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>800.698.9800</FONT>Worcester",	"cm.shtml"]
																				]					
															],										
															["Western Mass ",	[					
																					["<FONT STYLE='float:right;padding-right:3px;font-weight:normal;'>800.698.9800</FONT>Pittsfield",	"wm.shtml"]
																				]
															]															
														 ]
										],
										["Promotions",[["Save Up To 5 Percent","credit.shtml"],
													   ["Free Boston Mail<FONT SIZE=1> </FONT>Run","mailrun.asp"]
													  ]
										],
										["Gift Basket Delivery","baskets.shtml"]
									],
									[
										["Instant Rates","order/quotemaker.asp"],
										["Scheduled Run","routed.shtml"],
										["Get Discounts","credit.shtml"],
										["Request Rate Sheets","ratesheet.asp"]
										
									]
							
								]); 




