// Used for drop down navigation menus


var imagePath = "images/";
var mnuSelected = "";
var rightx = 0;
var leftx = 0;
var righty = 0;

// Sets the propeties of each menu item.  
// text is the actual displayed text, link is the hyperlink for the menu item,
// target will specify a target frame.

function menuItem(text, link, target){
	this.text = text;
	this.link = link;
	if (target) {
		this.target = target;
	} else {
		this.target = "PageContent";
	}
}

// Sets up a new instance of a menu class containing properties and methods for its items.

function menu(){
	var itemArray = new Array();
	var args = menu.arguments;
	this.name = args[0];
	for(i=1; i<args.length; i++){
		itemArray[i-1] = args[i];
	}
	this.menuItems = itemArray;
	this.write = writeMenu;
	this.position = positionMenu;
}

// Positions the drop down on the screen

function positionMenu(top,left,width) {
	this.top = top;
	this.left = left;
	this.width = width;
}

// Calculates the desired left hand position of the drop down menu in relation to its heading.  Different
// properties for Netscape 4.x

function calcLeftPos(element,indent) {
	var leftpos = 0;
	
	if (document.layers) {
		leftpos = getElement('mnuHeadings').document.layers[element].pageX + indent;
		
	} else {
		leftpos = getElement(element).offsetLeft + indent;	
	}
	return leftpos;
}

// Calculates the desired top position of the drop down menu in relation to its heading.  Different
// properties for Netscape 4.x

function calcTopPos(element) {
	var toppos = 0;
		
	if (document.layers) {
		toppos = getElement(element).clip.height;
	} else {
		toppos = getElement(element).offsetHeight;
	}
	return toppos-5;
}

// Displays the drop down menu using its visibility property.  
// Usually called from onMouseOver event of menu heading.  

function showMenu(menu,leftpos,toppos) {

	var leftindent = 5;	
	var bannerHeight = 65;
	var subMenuID = getElement(menu);
	
	if (getElement('esbanner')) {
		bannerHeight = calcTopPos('esbanner');
	}
		
	if (mnuSelected != "" && mnuSelected != menu) {
		hideMenu();
	}
	
	if (document.getElementById) {
		subMenuID.style.width = subMenuID.childNodes[0].clientWidth + 16;
	} else if (document.all) {
		subMenuID.style.width = subMenuID.children[0].clientWidth + 16;
	} 
	
	
	if (leftpos != null) {
		if (document.layers) {
			subMenuID.left = leftpos;
		} else {
			if ((parseInt(subMenuID.style.left) + parseInt(subMenuID.style.width)) >= (document.body.clientWidth - 10)) {
				var fitleft = document.body.clientWidth - parseInt(subMenuID.style.width);
				subMenuID.style.left = fitleft;
			} else {
				subMenuID.style.left = leftpos;
			}
		}
	}
			
	if (toppos != null) {
		if (document.layers) {
			subMenuID.top = toppos + bannerHeight;
		} else {
			subMenuID.style.top = toppos + bannerHeight;
		}
	}
	
	if (document.layers) {
		leftx = subMenuID.left;
		rightx = leftx + subMenuID.clip.width;
		righty = subMenuID.top + subMenuID.clip.height;
		subMenuID.visibility = 'show';
	} else {
		subMenuID.style.visibility = 'visible';
	}
	
	mnuSelected = menu;
}

// Hide the drop down menu from view.
// Usually called from onMouseOut/onMouseClick events to hide the drop down menu.

function hideMenu(e) {
	if (mnuSelected) {
		if (document.getElementById) {
			getElement(mnuSelected).style.visibility = 'hidden';
		} else if (document.all) {
			if (event.srcElement.tagName != "A") {
				getElement(mnuSelected).style.visibility = 'hidden';
			}
		} else if (document.layers) {
			if (e) {
				var posX = e.pageX;
				var posY = e.pageY;
			
				if (posX > rightx || posX < leftx) {
					getElement(mnuSelected).visibility = 'hide';
				} else if (posY > righty) {
					getElement(mnuSelected).visibility = 'hide';
				}
			} else {
				getElement(mnuSelected).visibility = 'hide';
			}
		}
	}
}

// Causes drop-down to dissappear when mouse moves out of menuheading area.  This is
// separate to hideMenu to prevent menus hanging around on IE4.

	function hideMenuHeading() {
		if (mnuSelected) {
			getElement(mnuSelected).style.visibility = 'hidden';
		}
	}
		
// Builds the drop-down menu using the information passed in.  Keeps it hidden initially, ready
// to be displayed onMouseOver.

function writeMenu() {
	
	if (document.layers) {
		var menuText = '<layer id="';
	} else {
		var menuText = '<div id="';
	}
	menuText += this.name;
	if (document.layers) {
		menuText += '" visibility="hide" z-index="1"'; 
	} else {
		menuText += '"  style="';
		menuText += 'position:absolute;z-index:1;visibility:hidden;background-color:#eeeeee;top: ';
		menuText += this.top;
		menuText += ';left: ';
		menuText += this.left + '"';
	}
	menuText += '>';
	menuText += '<table cellpadding="0" cellspacing="0" border="0" width="';
	menuText += this.width;
	menuText += '" onClick="hideMenu();" onMouseOver="showMenu(mnuSelected,null,null)" onMouseOut="hideMenu();">';
	for(i=0; i<this.menuItems.length; i++){
		menuText += '<tr bgcolor="#eeeeee">';
		menuText += '<td width="5px" class="menuside">&nbsp;</td>';
		menuText += '<td class="menulink" nowrap="nowrap"><a style="font-size:11px;font-weight:bold;color:#ff6600;text-decoration:none" ';
		menuText += 'target="' + this.menuItems[i].target + '" class="menulink"  href="' + this.menuItems[i].link + '">';
		menuText += this.menuItems[i].text + '</a></td>';
		menuText += '<td width="5px" class="menuside">&nbsp;</td>';
		menuText += '</tr>';
	}
	//Bottom section - usually adds images
	/*
	menuText += '<tr bgcolor="#cccccc" valign="top"><td width="5px" class="menuside" bgcolor="#cccccc"><img src="' + imagePath + 'mnu_bottomleft.gif" border="0"></td><td ';
	if (document.layers) {menuText += ' width="98%"'};
	menuText += ' bgcolor="#cccccc" class="menuside">&nbsp;</td><td><img border="0" src="' + imagePath + 'mnu_bottomright.gif"></td></tr>';
	*/
	menuText += '</table>';
	if (document.layers) {
		menuText += '</layer>';
	} else {
		menuText += '</div>';								
	}
	
	document.write(menuText);
	document.close();	
}

// Gets a handle on an element that has an ID assigned to it.  Different browsers grab elements
// in different ways, but this covers IE4+ and NS4+.

function getElement(elementId) {
	if (document.getElementById) {
		return document.getElementById(elementId);
	} else if(document.all) {
		return document.all(elementId);
	} else {
		return document.layers[elementId];
	}
}

// Capture mouse move event in Netscape 4 to aid in release of drop down.

if (document.layers)
{
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove = hideMenu;
}






