var lastTargetToShow = 0;
var lastDivToShow = 0;
var oMenuTimeOut;

var MENUDELAY_APPEAR = 1000; //Delay for the Sub-Menus to show up!
var MENUDELAY_DISAPPEAR = 350; //Delay for the Sub-Menus to show up!

function ShowDiv(tstuff, stuff, offX, offY)
{
  var celltospawn = document.getElementById(tstuff);
  var thingtospawn = document.getElementById(stuff);
  var offTemp = Element.cumulativeOffset(celltospawn);
  var tempy = offTemp.top;
  var tempx = offTemp.left;
  thingtospawn.style.left = (tempx + offX) + "px";
  thingtospawn.style.top = (tempy + offY) + "px";
  thingtospawn.style.visibility = "visible";
}

function ShowDivEx(tstuff, stuff, offX, offY, bIsRight)
{
  var celltospawn = document.getElementById(tstuff);
  var thingtospawn = document.getElementById(stuff);
  var offTemp = Element.cumulativeOffset(celltospawn);
  var tempy = offTemp.top;
  var tempx = offTemp.left;
  if(bIsRight == true)
  {
    thingtospawn.style.left = (tempx + offX + Element.getWidth(celltospawn) - Element.getWidth(thingtospawn)) + "px";
    thingtospawn.style.top = (tempy + offY) + "px";
    thingtospawn.style.visibility = "visible";
  }
  else
  {
    thingtospawn.style.left = (tempx + offX) + "px";
    thingtospawn.style.top = (tempy + offY) + "px";
    thingtospawn.style.visibility = "visible";
  }
}

function HideDiv(tstuff, stuff)
{
  var thingtospawn = document.getElementById(stuff);
  if (thingtospawn)
    thingtospawn.style.visibility = "hidden";
}

function HoldMenu(menuID)
{
  if(document.lastDivToShow == menuID)
  {
    clearTimeout(document.oMenuTimeOut);
  }
}

function ReleaseMenu()
{
  document.oMenuTimeOut = setTimeout("MenuTimeOut()", MENUDELAY_DISAPPEAR);
}

function MenuTimeOut()
{
  HideDiv(document.lastTargetToShow, document.lastDivToShow);
}

function MenuDisplay(idPlaceToShow, idDivToShow, offX, offY)
{
  if(document.lastDivToShow == idDivToShow)
  {
    clearTimeout(document.oMenuTimeOut);
  }
  else if(document.lastDivToShow != 0)
  {
    clearTimeout(document.oMenuTimeOut);
    MenuTimeOut();
  };
  document.lastDivToShow = idDivToShow;
  document.lastTargetToShow = idPlaceToShow;
  ShowDiv(idPlaceToShow, idDivToShow, offX, offY);
}

function MenuDisplayEx(idPlaceToShow, idDivToShow, offX, offY, bIsRight)
{
  if(document.lastDivToShow == idDivToShow)
  {
    clearTimeout(document.oMenuTimeOut);
  }
  else if(document.lastDivToShow != 0)
  {
    clearTimeout(document.oMenuTimeOut);
    MenuTimeOut();
  };
  document.lastDivToShow = idDivToShow;
  document.lastTargetToShow = idPlaceToShow;
  ShowDivEx(idPlaceToShow, idDivToShow, offX, offY, bIsRight);
}

function MenuOut()
{
  document.oMenuTimeOut = setTimeout("MenuTimeOut()", MENUDELAY_DISAPPEAR);
}
