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

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

var nav_start_slide_speed = 10;
var nav_slide_speed;
var nav_slide_timeout = null;
var nav_end_position = 45;
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;
  curnav.style.top = nav_position;
  nav_slide_timeout = setTimeout('slide()', 10);

  if (nav_position >= nav_end_position)
    {
      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;

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


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

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


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

function nav_showsub(nav, upnav)
{
  clearTimeout(nav_hidetimeout);
  clearTimeout(subnav_hidetimeout);

  var navref = document.getElementById(nav);
  nav_hidecursub();

  var upnavref = document.getElementById(upnav);
  var i = parseInt(new String(upnavref.style.left).replace(/px/, '')) - menu_width;
  navref.style.left = i - 1;

  navref.style.visibility = 'visible';
  cursubnav = navref;
}



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

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


// подсветить пункт меню

function nav_highlight_item(obj)
{
  if (obj != null)
    {
      obj.style.color = nav_highlight_col;
      obj.style.fontWeight = 'normal';
      obj.style.background = nav_highlight_pic;
      //obj.style.backgroundColor = nav_highlight_bg;
    }
}


// убрать подсветку с пункта меню

function nav_lowlight_item(obj)
{
  if (obj != null)
    {
      obj.style.color = nav_lowlight_col;
      obj.style.fontWeight = 'normal';
      obj.style.background = nav_lowlight_pic;
      //obj.style.backgroundColor = nav_lowlight_bg;
    }
}


function nav_over()
{  
  clearTimeout(nav_hidetimeout);
}


function nav_out()
{
  nav_delayhide();
}


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


// мышь над субменю

function nav_sub_over()
{
  clearTimeout(subnav_hidetimeout);
  clearTimeout(nav_hidetimeout);
}


// мышь ушла с субменю

function nav_sub_out()
{
  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_subitem_out(subnav)
{
   nav_sub_out();
   nav_lowlight_item(cursubitem);
}


function nav_subitem_over(subitem)
{
   nav_sub_over(subitem.id);
   highlight_subitem(subitem);
}


function highlight_subitem(subitem)
{
   clearTimeout(nav_hidetimeout);
   clearTimeout(subnav_hidetimeout);
   nav_lowlight_item(cursubitem);
   nav_highlight_item(subitem);
   cursubitem = subitem;
}

