//korekce pozice
var left             = 0;                 
var top              = 0; 
// time
var timeOff          = 600; 

/*------------------------*/
var idMenu           = 'menu';            
var classLevel_1     = 'menu_set';         
var idULactive       = 'active-menu';     
var autoIDmauseEvent = 'mause-event-menu';             
var timeActive       = true;                     
var nodeMenu = null;
var liActive = null;
var liArray1 = new Array;
var menuWidth = 0;
var idTime;
var opera6x = window.opera && !document.createComment;

var indexView = 1;
var akctiveLiNode = null;
var idNahoruOn;
var maxView = 5;
var save = true;

window.onload = onloadDoc;

function onloadDoc(){
  if(document.getElementById && document.getElementsByTagName && window.clearTimeout && !opera6x){
    if(document.getElementById(idMenu)){
      onloadNodeMenu();
    }
  }
  save = false;
  return true;
}
  
function onloadNodeMenu(){
  nodeMenu = document.getElementById(idMenu);
  menuWidth = nodeMenu.offsetWidth;
  onloadNodelevel_1();
}
  
function onloadNodelevel_1(){
  var linode = nodeMenu.getElementsByTagName('LI');
  var leftPozition = 0;
  var x = 0;
  
  for(var i = 0;i <= linode.length-1; i++){
    if(linode[i].className == classLevel_1){
      linode[i].pozLeft = leftPozition;
      leftPozition += linode[i].offsetWidth;
      linode[i].pozTop = linode[i].offsetHeight;
      linode[i].index = x;
      liArray1[x] = linode[i];
      x++;
    }
  }
}
  
function subMenuOn(node){
  if(save)return
  node = document.getElementById(node);
  var ulNode = node.getElementsByTagName('UL');
  var liNode = ulNode[0].getElementsByTagName('LI');
  var ind = 0;
  
  if(!node.indexView) node.indexView = 1

  liActive = node.index;
  if(timeActive){
    window.clearTimeout(idTime);
    subMenuTimeOff();
  }
  if(node.id != idULactive)node.getElementsByTagName('A')[0].className = 'active';
  if(ulNode[0]){
    //ulNode[0].style.visibility = 'visible';
    ulNode[0].style.display = 'block';
    if(ulNode[0].offsetWidth + node.pozLeft < menuWidth)ulNode[0].style.left = node.pozLeft + left + 'px';
    else ulNode[0].style.left = menuWidth - ulNode[0].offsetWidth + 'px';
    ulNode[0].style.top = node.pozTop + top + 'px';
    
    if(node.indexView)indexView = node.indexView
    else indexView = 1;
    sumView = 0
    if(liNode){
      if(liNode.length > maxView){
        for(ind=0; ind < liNode.length; ind++){
          if(liNode[ind].className == 'menu_up'){
            if(indexView > 1)liNode[ind].getElementsByTagName('DIV')[0].className = 'active';
            else liNode[ind].getElementsByTagName('DIV')[0].className = 'static';
            continue;
          }
          
          if(liNode[ind].className == 'menu_down'){
            if(liNode.length - node.indexView-2 >= maxView)liNode[ind].getElementsByTagName('DIV')[0].className = 'active';
            else liNode[ind].getElementsByTagName('DIV')[0].className = 'static';
            continue;
          }

          if(liNode[ind].className != 'menu_up' && liNode[ind].className != 'menu_down'){
            if(sumView < maxView && indexView <= ind){
              liNode[ind].style.display = 'inline';
              sumView++
            }
            else liNode[ind].style.display = 'none';
          }
        }
      }
    }
  }
  
}
 
function subMenuOff(node){
  if(timeActive)idTime = window.setTimeout('subMenuTimeOff()', timeOff);
    else subMenuTimeOff();
}
  
function subMenuTimeOff(){
  var ulNode;
  for(var i=0;i<=liArray1.length-1; i++){
    ulNode = liArray1[i].getElementsByTagName('UL');
    //if(ulNode[0])ulNode[0].style.visibility = 'hidden';
    if(ulNode[0])ulNode[0].style.display = 'none';
    liArray1[i].getElementsByTagName('A')[0].className = '';
  }
}
//nahoru
function nahoruOn(id){
  nahoruOnTime(id)
  idNahoruOn = window.setInterval('nahoruOnTime(\''+id+'\')', 100*4);
}
function nahoruOn2(id){
  clearInterval(idNahoruOn)
  idNahoruOn = window.setInterval('nahoruOnTime(\''+id+'\')', 100*1.5);
}
function nahoruOnTime(id){
  node = document.getElementById(id);
  if(!node.indexView) node.indexView = 1
  node.indexView--;
  subMenuOn(id);
}
function nahoruOff(node){
  clearInterval(idNahoruOn);
}
function nahoruOff2(node){
  clearInterval(idNahoruOn);
  nahoruOn(node)
}
//dolu
function doluOn(id){
  doluOnTime(id)
  idNahoruOn = window.setInterval('doluOnTime(\''+id+'\')', 100*4);
}
function doluOn2(id){
  clearInterval(idNahoruOn)
  idNahoruOn = window.setInterval('doluOnTime(\''+id+'\')', 100*1.5);
}
function doluOnTime(id){
  node = document.getElementById(id);
  if(!node.indexView) node.indexView = 1
  var ulNode = node.getElementsByTagName('UL');
  var liNode = ulNode[0].getElementsByTagName('LI');
  if(liNode.length - node.indexView-2 < maxView)return
  node.indexView ++;
  subMenuOn(id);
}
function doluOff(node){
  clearInterval(idNahoruOn);
}
function doluOff2(node){
  clearInterval(idNahoruOn);
  doluOn(node)
}

