
	/*************************************************************************
	  This code is from Dynamic Web Coding at http://www.dyn-web.com/
	  Copyright 2003 by Sharon Paine 
	  See Terms of Use at http://www.dyn-web.com/bus/terms.html
	  regarding conditions under which you may use this code.
	  This notice must be retained in the code as is!
	*************************************************************************/
	
	var menuLayers = {
	  timer: null,
	  activeMenuID: null,
	  show: function(id, vOffset) {
			var adjustmentFactor = 1.5; //Has to do with font size of menu items
			var mnu = document.getElementById("menu_" + id);
			var img = document.getElementById(id);
			var pos = this.findPosition(img);
			var x = pos[0];
			var y = pos[1];
			x += img.width + 1;
			y -= vOffset * adjustmentFactor;
			if (!mnu) return;
			this.activeMenuID = "menu_" + id;
			if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
			if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
			viewport.getAll();
			this.positionTwo(mnu,x,y);
	  },
	  
	  hide: function() {
			this.clearTimer();
			if (this.activeMenuID && document.getElementById) 
		  	this.timer = setTimeout("document.getElementById('"+menuLayers.activeMenuID+"').style.display = 'none'", 200);
	  },
	  
	  positionTwo: function(mnu,x,y) {
	  	mnu.style.left = x + "px";
	  	mnu.style.top = y + "px";
	  	this.timer = setTimeout("document.getElementById('" + menuLayers.activeMenuID + "').style.display = 'block'", 200);
	  },
	  
	  mouseoutCheck: function(e) {
		e = e? e: window.event;
		// is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
		var mnu = document.getElementById(menuLayers.activeMenuID);
		var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
		if ( mnu != toEl && !menuLayers.contained(toEl, mnu) ) menuLayers.hide();
	  },
	  
	  // returns true of oNode is contained by oCont (container)
	  contained: function(oNode, oCont) {
		if (!oNode) return; // in case alt-tab away while hovering (prevent error)
		while ( oNode = oNode.parentNode ) 
		  if ( oNode == oCont ) return true;
		return false;
	  },
	
	  clearTimer: function() {
		if (menuLayers.timer) clearTimeout(menuLayers.timer);
	  },
	  
		findPosition: function(oLink) {
			for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
			  posX += oLink.offsetLeft;
			  posY += oLink.offsetTop;
			}
			return [ posX, posY ];
		}
	  
	}