var menuLayers = {
  
  // public methods
  show: function (id) 
  {
    var mnu = document.getElementById ? document.getElementById(id) : null;
    if (!mnu) 
      return;

    this._activeMenuID = id;

    if ( mnu.onmouseout == null ) 
      mnu.onmouseout = this._mouseoutCheck;
    if ( mnu.onmouseover == null ) 
      mnu.onmouseover = this._clearTimer;

    // find 'a' element's horizontal position
    var aElement = document.getElementById("a-" + id);
    
    // menu should have the same horizontal position as 'a' ( + offset) 
    mnu.style.left = ( this._getElementXPos(aElement) + this._menuXOffset ) + "px";
    // vertical position is constant 
    mnu.style.top = this._top + "px";

    this._timer = 
      setTimeout("document.getElementById('" + menuLayers._activeMenuID + "').style.visibility = 'visible'", 200);
  },
  
  hide: function() 
  {
    this._clearTimer();
    
    if (this._activeMenuID && document.getElementById) 
      this._timer = setTimeout("document.getElementById('"+menuLayers._activeMenuID+"').style.visibility = 'hidden'", 200);
  },
  
  // private methods
  _getElementXPos: function (obj)
  { 
    var x = 0; 
    do 
    { 
      x += obj.offsetLeft; 
      obj = obj.offsetParent;
    } while (obj); 
  
    return x;
  },

  _mouseoutCheck: function(e) 
  {
    e = e ? e : window.event;
    var menu = document.getElementById(this._activeMenuID);
    var elem = e.relatedTarget ? e.relatedTarget : e.toElement;

    if ( menu != elem && !menuLayers._componentOf(elem, menu) ) 
      menuLayers.hide();
  },
  
  // returns true of 'element' is a component of 'menu'
  _componentOf: function(element, menu) 
  {
    if (!element) 
      return; // in case alt-tab away while hovering (prevent error)

    while ( element = element.parentNode ) 
      if ( element == menu ) 
        return true;

    return false;
  },

  _clearTimer: function() 
  {
    if (menuLayers._timer) 
      clearTimeout(menuLayers._timer);
  },
  
  // private members
  _timer: null,
  _activeMenuID: null,
  
  // private constants
  _menuXOffset: 0,
  _top: 124
}
