var Inav = Class.create();
Inav.prototype = {
   initialize: function() {
      if (!$('olefa_inav')) { return; }

      this.inav_open_event    = this.inav_open.bindAsEventListener(this);
      this.inav_close_event   = this.inav_close.bindAsEventListener(this);

      Event.observe($('olefa_inav'),                       'click',     this.inav_open_event   );
      Event.observe($$('#olefa_inav li.inav-titlebar')[0], 'click',     this.inav_close_event  );

      var first_menu = $($('olefa_inav').firstChild);

      first_menu.style.visibility = 'hidden';
      first_menu.style.display = 'block';

      var arrow_top = Element.getHeight($$('#olefa_inav a')[0])/2-8 + 'px';
      $$('#olefa_inav img.olefa-inav-arrow').each(function(img) {
         img.style.top = arrow_top;
      });

      $$('#olefa_inav li').each(function(menu) {
         menu.addClassName('ie6-hover');
      });

      $$('#olefa_inav ul').each(function(menu) {
         var menu_parent = $(menu.parentNode);
         if (menu_parent.id == 'olefa_inav') { return; }

         menu.style.left = menu_parent.getDimensions().width+'px';

         var menu_width  = menu.getDimensions().width+'px';

         $A(menu.childNodes).each(function(item) {
            item.style.width = menu_width;
         });

      });

      $$('#olefa_inav li').each(function(menu) {
         menu.removeClassName('ie6-hover');
      });

      first_menu.style.display = 'none';
      first_menu.style.visibility = '';
   },

   inav_open: function(e) {
      $($('olefa_inav').firstChild).style.display = 'block';
   },

   inav_close: function(e) {
      Event.stop(e);
      $($('olefa_inav').firstChild).style.display = 'none';
   }
}

Event.observe(window, 'load', function() {
   new Inav();
});