var noHideMenuTimer;

function noMouseUp (url) {
  var target = '_self';
  if (url != null) {
    window.open (url, target);
  }
}

function noMouseOver (menuObj) {
  clearTimeout (noHideMenuTimer); 
  var menuId = menuObj.id.substring(0,menuObj.id.indexOf("-"));
  noHideAllMenus(menuId);
  noShowMenus(menuObj.id);
}

function noMouseOut (menuObj) { 
  var menuId = menuObj.id.substring(0,menuObj.id.indexOf("-"));
  var cmdline = "noHideAllMenus('" + menuId +"')";
  noHideMenuTimer = setTimeout (cmdline,500);
}

function noShowMenus(menuId) {
  if (menuId.lastIndexOf("-") != -1) {
    noShowMenus(menuId.substring(0,menuId.lastIndexOf("-")));
  }
  var menuObj;
  menuObj = document.getElementById(menuId);
  if (menuObj) {
    menuObj.className = "selected";
  }
  var subMenuObj;
  subMenuObj = document.getElementById(menuId + "-sub");
  if (subMenuObj) {
    noFixSubMenuPosition(subMenuObj);
    subMenuObj.style.visibility = "visible";
  }
}

function noHideAllMenus(menuId) {
  var i = 0;
  var menuObj;
  var subMenuObj;
  while (menuObj = document.getElementById(menuId + "-" + i)) {
    menuObj.className = "";
    subMenuObj = document.getElementById(menuObj.id + "-sub");
    if (subMenuObj) {
      noHideAllMenus(menuObj.id);
      subMenuObj.style.visibility = "hidden";
    }
    i++;
  }
}


function noFixSubMenuPosition (menuObj) {
  var parentMenuObj;
  parentMenuObj = document.getElementById(menuObj.id.substring(0,menuObj.id.lastIndexOf("-")));
  var position = getObjectPosition(parentMenuObj);
  if (parentMenuObj.id.lastIndexOf("-") == parentMenuObj.id.indexOf("-")) {
    menuObj.style.top = position.bottom  + "px";
    menuObj.style.left = position.left  + "px";
    if (menuObj.style.width < position.right - position.left) {
      menuObj.style.width = position.right - position.left + "px";
    }
  } else {
    menuObj.style.top = position.top -1 + "px";
    menuObj.style.left = position.right -2 + "px";
  }
}

function getObjectPosition(obj) {
    var offsetTrail = obj;
    var offsetLeft = 0;
    var offsetTop = 0; 
   // Fix IE's CSS position problem
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop, right: offsetLeft + obj.offsetWidth, bottom: offsetTop + obj.offsetHeight};
}



