var myCMS_LastSubMenuName = 'nothing';
var myCMS_LastTimeOut='';

function myCMS_getElementPosition(pElem) {
  var offsetTrail = pElem;
  var offsetLeft = 0;
  var offsetTop = 0;
  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};
}

function myCMS_ShowMenu(menuID) {
  if (myCMS_LastTimeOut!='') {
    clearTimeout(myCMS_LastTimeOut); // Clear any previous timeout!
    myCMS_LastTimeOut='';
  };

  if (myCMS_LastSubMenuName!='nothing') {
    refLastSubMenu = document.getElementById(myCMS_LastSubMenuName);
    if (refLastSubMenu) refLastSubMenu.style.visibility = 'hidden';
  };
  
  refNewMainMenu = document.getElementById('myCMS_'+menuID);
  refNewSubMenu = document.getElementById('myCMS_sub_'+menuID);

  if (refNewSubMenu) {
    if (refNewMainMenu) {
      refNewSubMenu.style.visibility = 'visible';
      if (document.all) {
        /* IE does things differently offcourse... */
        newleft = myCMS_getElementPosition(refNewMainMenu).left;
      } else {
        newleft = refNewMainMenu.offsetLeft;
      };      
      refNewSubMenu.style.left = newleft+'px';
    }
  
    myCMS_LastSubMenuName='myCMS_sub_'+menuID;
  }
}

function myCMS_TimeHideMenu() {
  if (myCMS_LastTimeOut!='') {
    clearTimeout(myCMS_LastTimeOut); // Clear any previous timeout!
    myCMS_LastTimeOut='';
  };

  myCMS_LastTimeOut=setTimeout("myCMS_HideMenu();",1000); // We want the menu to be hidden after one second..
}

function myCMS_HideMenu() {
  refLastSubMenu = document.getElementById(myCMS_LastSubMenuName);

  if (refLastSubMenu) refLastSubMenu.style.visibility = 'hidden';

  myCMS_LastSubMenuName = 'nothing';
}
