{
   var actual_navig, prev_navig;
   var items_space   = 5;
   
   function navig_mousedown(ev) {
      document.onselectstart = function(){return false;}
      return false;
   }
   function navig_mouseover(ev) {
      if (this.navig_id != actual_navig) {
         jslSetAttribute(this, 'backgroundColor', '#A84300');
      }
   }
   function navig_mouseout(ev) { 
      if (this.navig_id != actual_navig) {
         jslSetAttribute(this, 'backgroundColor', 'transparent');
      }
      document.onselectstart = null;
   }
   
   function topNavigClick(id) { //{{{
      var e = jslObject('navigTopItem' + id);
      jslSetAttributes(e,
         'backgroundColor', null,
         'class', 'navigtopsel',
         'backgroundColor', 'transparent'
      );
      var l_bottom = jslObject('navigBottom');

      jslAnimationStop(l_bottom);
      jslSetTop(l_bottom, 0);
      
      if (prev_navig) {
         jslHide('navigBottom' + prev_navig);
      }
      if (actual_navig) {
         jslSetTop('navigBottom' + actual_navig, 0);
         if (actual_navig != id) {
            jslSetAttributes('navigTopItem' + actual_navig, 
               'class', 'navigtop'
            );
         }
      }
      jslSetAttributes('navigBottom' + id,
         'top', navig_bottom_height,
         'visibility', 'visible'
      );

      prev_navig     = actual_navig;
      actual_navig   = id;

      jslAnimation(l_bottom, 500, function(t) {
         jslSetTop(this, -t*navig_bottom_height);
      });
   } //}}}

   function navig_click(ev) { 
      if (this.navig_id != actual_navig) topNavigClick(this.navig_id); 
   }
   function navig_bottom_mouseover(ev) {
      jslSetAttribute(this, 'backgroundColor', '#909090'); 
      if (! this.popup && this.popup_a) createNavigPopup(this);
      if (this.popup) showPopupNavig(this.popup);
   }
   function navig_bottom_mouseout(ev) { 
      jslSetAttribute(this, 'backgroundColor', 'transparent'); 
      if (this.popup) {
         this.popup.hide = true;
         setTimeout('hidePopupNavig(' + this.popup.jslString + ')', 100);
      }
      document.onselectstart = null;
   }
   function navig_bottom_click(ev) {
      var re_javascript = /^javascript:(.*)$/;
      var res = re_javascript.exec(this.link);
      if (res)
         eval(res[1]);
      else
         if ( this.link ) window.location.href = this.link;
   }
   
   var l_navig = jslObject('navig');
   navig_bottom = jslGetTop(l_navig) + jslGetHeight(l_navig);
   
   //horny panel
   var l_top_v   = jslCreateChild(l_navig, "navigTopView");
   var l_top     = jslCreateChild(l_top_v, "navigTop");
   jslSetAttributes(l_top_v,
      'width', navig_width,
      'height', navig_top_height,
      'left', 20,
      'top', 2,
      'overflow', 'hidden'
   );
   jslSetAttributes(l_top,
      'width', navig_width,
      'height', navig_top_height,
      'top', -navig_top_height
   );

   //spodny panel
   var l_bottom_v   = jslCreateChild(l_navig, "navigBottomView");
   var l_bottom     = jslCreateChild(l_bottom_v, "navigBottom");
   jslSetAttributes(l_bottom_v,
      'width', navig_width,
      'height', navig_bottom_height,
      'left', 20,
      'top', 2+navig_top_height,
      'overflow', 'hidden'
   );
   jslSetAttributes(l_bottom,
      'width', navig_width,
      'height', navig_bottom_height*2
   );

   //vytvorenie poloziek
   var i, x0, e, dx;
   var x_popup = jslGetLeft(l_bottom_v);
   var y_popup = jslGetTop(l_bottom_v);
   for (i = 1, x0 = 0; i <= a_navig.length; i++) {
      //polozka horneho panelu
      e = jslCreateChild(l_top, "navigTopItem" + i)
      e.navig_id = i;
      jslSetAttributes(e, 
         'left', x0, 
         'top', 0, 
         'height', navig_top_height,
         'class', 'navigtop',
         'html', '&nbsp;' + a_navig[i-1] + '&nbsp;'
      );
      jslSetHandler(e, 'mousedown', navig_mousedown);
      jslSetHandler(e, 'mouseover', navig_mouseover);
      jslSetHandler(e, 'mouseout', navig_mouseout);
      jslSetHandler(e, 'click', navig_click);
      x0 += jslGetWidth(e) + items_space;
      
      //a odpvoedajuce polozky zo spodneho panelu
      var l_b = jslCreateChild(l_bottom, 'navigBottom' + i);
      jslSetAttributes(l_b,
         'visibility', 'hidden',
         'left', 0,
         'top', 0, 
         'width', navig_width,
         'height', navig_bottom_height
      );
      var a_b = eval('a_navig' + i);
      if (a_b.length > 1 )
      {
         var ii = a_b.length, xx0 = 0;

         function createBottomItem() { // {{{
            var e = jslCreateChild(l_b, "navigBottomItem" + i + 'x' + ii);
            jslSetAttributes(e,
               'class', 'navigBottom',
               'left', xx0, 
               'top', 0, 
               'height', navig_bottom_height,
               'html', '&nbsp;' + a_b[ii-1][0] + '&nbsp;'
            );
            e.navig_id     = ii;
            e.par_navig_id = i;
            e.link         = a_b[ii-1][1];
            e.popup_a      = a_b[ii-1][2];
            if (e.popup_a) {
               e.x_popup   = x_popup;
               e.y_popup   = y_popup;
            }
            
            jslSetHandler(e, 'mousedown', navig_mousedown);
            jslSetHandler(e, 'mouseover', navig_bottom_mouseover);
            jslSetHandler(e, 'mouseout', navig_bottom_mouseout);
            jslSetHandler(e, 'click', navig_bottom_click);

            return e;
         } // }}}
      
         var l_e = createBottomItem();
         xx01 = jslGetWidth(l_e) + items_space;
         var max_width = navig_width - xx01;
         for (ii=1, xx0=0; ii < a_b.length; ii++) {
            e = createBottomItem();
            xx0 += jslGetWidth(e) + items_space;
            if (xx0 > max_width) {
               xx0 -= jslGetWidth(e) + items_space;
               jslRemoveObject(e);
            }
         }
         jslSetLeft(l_e, xx0);
         xx0 += xx01;
         
         dx = Math.round((navig_width -  xx0) / 2);
         for (ii=1; ii <= a_b.length; ii++) {
            var e = jslObject("navigBottomItem" + i + 'x' + ii);
            jslSetLeft(e, jslGetLeft(e)+dx);
         }
      }
   }
   dx = Math.round((navig_width - x0) / 2);
   for (i=1; i <= a_navig.length; i++) { 
      var e = jslObject('navigTopItem' + i);
      jslSetLeft(e, jslGetLeft(e)+dx);
   }
 
   jslPostRun(
      function (){
         jslShow(l_navig);
         jslAnimation(l_top, 500, function(t) {
            jslSetTop(this, (t-1)*navig_top_height);
         });
         topNavigClick(navig_actual_menu);
      }
   );
}


function hidePopupNavig(p) {
   if (p.hide && (jslGetAttribute(p, 'visibility') == 'visible')) {
      jslHide(p);
      jslPopupClose();
   }
}

function showPopupNavig(p) {
   p.hide = false;
   if (jslGetAttribute(p, 'visibility') != 'visible') {
     jslPopupOpen();
     jslShow(p);
   }
}

function createNavigPopup(e) {
   //popup menu
   if (e.popup_a.length > 0) {
      var i = e.par_navig_id, ii = e.navig_id;
      e.popup = jslCreateChild('navig', "navigPopup" + i + 'x' + ii);

      jslSetHandler(e.popup, 'mouseover', function(ev) { this.hide = false; });
      jslSetHandler(e.popup, 'mouseout', function(ev) { 
         this.hide = true;
         setTimeout('hidePopupNavig(' + e.popup.jslString + ')', 100);
      });
      jslSetAttributes(e.popup,
         'left', jslGetLeft(e) + e.x_popup,
         'top', navig_bottom_height + e.y_popup,
         'width', 400,
         'height', 400,
         'backgroundColor', '#ffffff',
         'visibility', 'hidden'
      );
      var p_w = jslGetWidth(e) - 2, p_h = 2;
      for (i_p = 1; i_p <= e.popup_a.length; i_p++) {
         if (e.popup_a[i_p - 1]) {
            var p = jslCreateChild(e.popup, "navigPopup" + i + 'x' + ii + 'x' + i_p);
            jslSetAttributes(p,
               'left', 2,
               'top', p_h,
               'backgroundColor', '#b0b0b0',
               'html', '<div class=navigPopup>' + e.popup_a[i_p - 1][0] + '</div>'
            );
            p.link = e.popup_a[i_p - 1][1];
            jslSetHandler(p, 'mouseover', function(ev) { jslSetAttribute(this, 'backgroundColor', '#909090'); });
            jslSetHandler(p, 'mouseout', function(ev) { jslSetAttribute(this, 'backgroundColor', '#b0b0b0'); });
            jslSetHandler(p, 'click', navig_bottom_click );
            p_h += jslGetHeight(p) + 1;
         }
      }
      for (i_p = 1; i_p <= e.popup_a.length; i_p++) {
         if (e.popup_a[i_p - 1]) {
            var w = jslGetWidth("navigPopup" + i + 'x' + ii + 'x' + i_p);
            if (p_w < w) p_w = w;
         }
      }
      for (i_p = 1; i_p <= e.popup_a.length; i_p++) {
         if (e.popup_a[i_p - 1]) {
            jslSetWidth("navigPopup" + i + 'x' + ii + 'x' + i_p, p_w);
         }
      }
      jslSetAttributes(e.popup,
         'width', p_w + 4,
         'height', p_h + 1
      );
   }
}

