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!


//prototype-al együttműködés érdekében $("#... kiválasztás helyett jQuery("#

function ShowDiv(tstuff, stuff, offX, offY)
{
  var celltospawn = jQuery('#'+tstuff);
  var thingtospawn = jQuery('#'+stuff);
  var offTemp = celltospawn.offset();
  var tempy = offTemp.top;
  var tempx = offTemp.left;
  thingtospawn.css('left', (tempx + offX) + "px");
  thingtospawn.css('top', (tempy + offY) + "px");
  thingtospawn.css('visibility', "visible");
}

function ShowDivEx(tstuff, stuff, offX, offY, bIsRight)
{
  var celltospawn = jQuery('#'+tstuff);
  var thingtospawn = jQuery('#'+stuff);
  var offTemp = celltospawn.offset();
  var tempy = offTemp.top;
  var tempx = offTemp.left;
  if(bIsRight == true)
  {
    thingtospawn.css('left', (tempx + offX + celltospawn.width() - thingtospawn.width()) + "px");
    thingtospawn.css('top', (tempy + offY) + "px");
    thingtospawn.css('visibility', "visible");
  }
  else
  {
    thingtospawn.css('left', (tempx + offX) + "px");
    thingtospawn.css('top', (tempy + offY) + "px");
    thingtospawn.css('visibility', "visible");
  }
}

function HideDiv(tstuff, stuff)
{
  var thingtospawn = jQuery('#'+stuff);
  if (thingtospawn)
    thingtospawn.css('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);
}


function HoldSubMenu(menuID)
{
  if(document.lastSubDivToShow == menuID)
  {
    clearTimeout(document.oSubMenuTimeOut);
  }
}
