// всплывающие меню

// переменные
var curnav = null;
var curarr = null;
var nav_hidetimeout = null;
var cursubnav = null;
var subnav_hidetimeout = null;
var cursubitem = null;
var timeout = 50;
var menu_width = 140;

var nav_start_slide_speed = 8;
var nav_slide_speed;
var nav_slide_timeout = null;
var nav_end_position = 178;
var nav_position = 0;

var nav_highlight_col = 'White';
var nav_highlight_bg = '#638EBA'
var nav_lowlight_col = 'White';
var nav_lowlight_bg = '#dddacc';
var nav_highlight_pic = 'url(pic/menu/back4.gif)';
var nav_lowlight_pic = '';
var nav_offset = 12;


// показать стрелку - выделение меню

function arrow_show(name)
{
  var arr = document.getElementById(name);
  arr.style.visibility = 'visible';
}

function arrow_hide(name)
{
  var arr = document.getElementById(name);
  //arr.style.visibility = 'hidden';
}


// показать меню

function nav_show(name, anchorname)
{
  var nav = document.getElementById(name);
  clearTimeout(nav_hidetimeout);

  if (nav != curnav)
    {
      nav_hidecur();

      var el = document.getElementById(anchorname);
      var ol = - nav_offset + el.offsetLeft;
      while ((el = el.offsetParent) != null)
        { ol += el.offsetLeft; }

      var arrow = 'arr_' + new String(name).replace(/nav_/, '');
      arrow_show(arrow);
      curarr = arrow;
      
      nav.style.left = ol;
      nav.style.visibility = 'visible';
      curnav = nav;

      nav_position = -50;
      nav_slide_speed = nav_start_slide_speed;
      slide();
    }
}


// скольжение

function slide()
{
  // отрицательное ускорение
  if (nav_position > nav_end_position - 30) nav_slide_speed = 3;
  if (nav_position > nav_end_position - 20) nav_slide_speed = 2;
  if (nav_position > nav_end_position - 10) nav_slide_speed = 1;
  
  nav_position += nav_slide_speed;
  if (curnav) curnav.style.top = nav_position;
  nav_slide_timeout = setTimeout('slide()', 10);

  if (nav_position >= nav_end_position)
    {
      if (curnav) curnav.style.top = nav_end_position;
      clearTimeout(nav_slide_timeout);
    }
}

// спрятать текущее меню

function nav_hidecur()
{
  if (curnav != null)
    {
      if (cursubnav != null) nav_hidecursub();
      if (cursubitem != null) lowlight_item(cursubitem);
      arrow_hide(curarr);
      curarr = null;

      if (curnav) curnav.style.visibility = 'hidden';
      curnav = null;
      clearTimeout(nav_slide_timeout);
    }
}

// мышь ушла с пункта меню

function nav_item_out(nav)
{
 // nav_lowlight_item(nav);
  nav_delayhidesub();
  nav_delayhide();
}

function nav_delayhidesub()
{
   subnav_hidetimeout = setTimeout("nav_hidecursub();", timeout);
}

function nav_hidecursub()
{
  if (cursubnav != null)
    {
      cursubnav.style.visibility = 'hidden';
      nav_lowlight_item(cursubitem);
      cursubitem = null;
      cursubnav = null;
    }
}

function nav_out()
{
  nav_delayhide();
}

function nav_delayhide()
{
  nav_hidetimeout = setTimeout("nav_hidecur()", timeout);
}

// мышь над пунктом меню

function nav_item_over(nav, subnav, upnav)
{
  clearTimeout(nav_hidetimeout);
  //nav_highlight_item(nav);
  if (subnav != null) nav_showsub(subnav, upnav);
}

