var activeMenuID='';
// show layer
function showLayer(id,topm) {
	activeMenuID=id;
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
    if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
    mnu.style.top = topm;
    mnu.style.visibility = 'visible';
}
// check layer
function checkLayer(id,e) {
	e = e? e: window.event;
    activeMenuID = id;
    var mnu = document.getElementById? document.getElementById(id): null;
	if (!mnu) return;
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !contained(toEl, mnu)) hideLayer(activeMenuID);
}

// hide layer
function hideLayer(id) {
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
    activeMenuID = id;
    mnu.style.visibility = 'hidden';
}

//
function mouseoutCheck(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(activeMenuID);
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !contained(toEl, mnu)) hideLayer(activeMenuID);
  }

function contained(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;
}