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)+42;
    stopTime();
}

function show_block(id)
{	
	var object=document.getElementById('link_'+id);
	var obj=document.getElementById('submenu_'+id);
	obj.style.display = 'block';
   obj.style.position = 'absolute';
	obj.style.left=getPosX(object);
	obj.style.top=getPosY(object)+42;
	setTimeout( "hideMenuAll('submenu_"+id+"')" , 3000);	
}

// скрытие подменю
function hideMenuAll(id)
{
   var object=document.getElementById(id);
   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;
   }
}

function wind(w, h, file, param)
{     
   var l=(screen.width-w)/2;
   var t=(screen.height-h)/2;   
   var attrs="width="+w+", height="+h+", left="+l+", top="+t+", resizable=no, status=no, location=no, scrollbars=yes";   
   wnd_name='wnd'+(Math.round(Math.random()*10000));   
   var params=file+"?"+param;   
   wnd=window.open(params, wnd_name, attrs); 
   wnd.focus();
}
