var id_menu = '0'; // id всплывающего подменю
var timerOn = false;
var timerID; // переменная таймера
var delay=500; // задержка в мс

// получение абсолютных координат объекта
function getPosX(obj)
{
   var curleft = 0;
   if (obj.offsetParent)
   {
      while (obj.offsetParent)
      {
         curleft += obj.offsetLeft;
         obj = obj.offsetParent;
      }
   }
   else if (obj.x)
   {
      curleft += obj.x;
   }
   return curleft;
}

function getPosY(obj)
{
   var curtop = 0;
   if (obj.offsetParent)
   {
      while (obj.offsetParent)
      {
         curtop += obj.offsetTop;
         obj = obj.offsetParent;
      }
   }
   else if (obj.x)
   {
      curtop += obj.x;
   }
   return curtop;
}

// вывод подменю
function showMenu(id, obj)
{
    if (id==id_menu || id_menu=='0') {} else { document.getElementById(id_menu).style.display = 'none';}
    id_menu = id;
    var object=document.getElementById(id_menu);
    hideMenuAll(id_menu);
    object.style.display = 'block';
    object.style.position = 'absolute';
    object.style.left=getPosX(obj);
    object.style.top=getPosY(obj)+25;
    stopTime();
}

// скрытие подменю
function hideMenuAll(id)
{
   var object=document.getElementById(id_menu);
   object.style.display = 'none';
   stopTime ();
}

function hideMenu()
{
   startTime ();
}

// включение задержки скрытия подменю
function startTime()
{
   if (timerOn == false)
   {
      timerID=setTimeout( "hideMenuAll(id_menu)" , delay);
      timerOn = true;
   }
}

// Сброс параметров
function stopTime()
{
   if (timerOn)
   {
      clearTimeout(timerID);
      timerID = null;
      timerOn = false;
   }
}