function initMenu() {
   var currentMenu;
   var overMenu=false;
   var menuTop=$('#navigation ul').offset().top;
   var menuWidth=922;

   $('#navigation ul li').map(
      function() {
         var classname=$(this).attr('class');
         if (classname === 'active') {
            hiLightMenu($(this),true);
         }
      }
   );

   $('#filler').mouseenter(
      function(ev) {
         if ($(currentMenu).attr('id').substr(0,1)==='m'){
            hiLightMenu($('#'+$(currentMenu).attr('id')),false);
         }
      }
   );
   
   $('#navigation').mouseleave(
      function(ev) {
         if (ev.clientX < $(this).offset().left) {
            hideMenu(currentMenu,true);
         }
         if ($(currentMenu).attr('id').substr(0,1)==='m'){
            hiLightMenu($('#'+$(currentMenu).attr('id')),false);
         }
      }
   );
   
   $('#navigation ul li').mouseenter(
      function() {
         var smid='#s'+$(this).attr('id');
         var pos=$(this).offset();
         $(smid).css('left',pos.left);
         $('#submenus ul').map(
            function () {
               hideMenu($(this));
            });
         showMenu($(smid));
         currentMenu=$(smid);
         overMenu=true;
      }
   );

   $('#navigation ul li').mouseleave(
       function(ev) {
          var smid='#s'+$(this).attr('id');
          var pos=$(this).offset().top;
          $('#submenus ul').hide();
          if (ev.clientY > menuTop) {
             showMenu(currentMenu);
          }
          overMenu=false;
       }
    );
   
   $('#submenus ul').mouseleave(
      function() {
         hideMenu($(this));
         currentMenu=null;
         overMenu=false;
      }
   )
   
   $('#navigation ul li').map(
      function() {
         var that=this;
         var smName='#s'+$(this).attr('id');
         if (!$(smName).attr('id')) {
            $(that).mouseover(
               function() {
                  hiLightMenu($(that),true);
                  currentMenu=that;
               }
            );
            $(that).mouseout(
               function() {
                  hiLightMenu($(that),false);
                  currentMenu=null;
               }
            );
         }
      }
   );
}

function showMenu(menu) {
   menu.show();
   hiLightMenu(menu,true);
}

function hideMenu(menu,doFade) {
   if (doFade) {
      menu.fadeOut('slow');
   } else {
      menu.hide();
   }
   hiLightMenu(menu,false);
}

function hiLightMenu(menu,doHiLight) {
   var mid=menu.attr('id');   
   if (mid && mid.length > 2) {
      mid=mid.substr(1);
   }
   
   var classname=$('#'+mid).attr('class');
   var imgname=$('#'+mid+' img').attr('src');
   
   if (imgname === undefined) {
      return;
   }   

   if (doHiLight == true) {
      if (imgname.substr(imgname.length-6) != '_a.png')
      {
         imgname=imgname.substring(0,imgname.length-4)+'_a.png';
         $('#'+mid+' img').attr('src',imgname);
      }
   } else {
      if ((classname!='active') && (imgname.substr(imgname.length-6) === '_a.png')) {
         imgname=imgname.substring(0,imgname.length-6)+'.png';
         $('#'+mid+' img').attr('src',imgname);
      } 
   }
}

