/**
 * Main Javascript file for sos-jeu.ch
 *
 * Author: Antistatique.net, Gilles Doge
 * Date: 2010-04-15
 */
jQuery(function($){
   
   // Nice! Javascript is supported
   $('body').removeClass('no-js');
   
   // Main menu navigation (on hover)
   $("#menu ul.level0 > li").hoverIntent({
      over: function(evt){
         var $this = $(this)
         var menu = $this.find('ul:first');
         
         // set the background color of the parent element
         $this.css({ backgroundColor: '#565659' });
         
         menu.stop(true, true).slideDown(300, function(){
            $this.addClass("active");
         });
      },
      
      out: function(evt){
         var $this = $(this)
         var menu = $this.find('ul:first');
         menu.stop(true, true).slideUp(300, function(){
            // revert smoothly the white color of the parent li
            $this.removeClass("active").animate({backgroundColor: 'transparent'}, 100);
         });
      },
      sensitivity: 7,
      interval: 150,
      timeout: 500
   });
   
   // Submenu navigation (on click)
   $('#menu ul.level1 > li > a').click(function(evt){
      
      var $parent = $(this).parent();
      var hasSubmenu = ($parent.find("ul").size() > 0);
      if(hasSubmenu)
      {
         var submenu = $parent.find('ul:first');
         if(!submenu.is(':visible'))
         {
            // open submenu
            submenu.slideDown('normal', function() {
               $parent.addClass("active");
            });
         } else {
            // close submenu
            submenu.slideUp('normal', function() {
               $parent.removeClass("active");
            });
         }
         
         // prevent browser default action
         evt.preventDefault();
      }
   });
   
})
