/* if user is using IE6 offer Google Chrome */
if(!window.XMLHttpRequest) { alert('Your browser is obsolete. Click OK to download Google Chrome, a faster and safer browser.'); window.location = 'http://www.google.com/chrome/'; }

jQuery(document).ready(function() {
  
  /* Main menu */
  jQuery('#header-container .menu > ul > li > a').css({'opacity':1.0});
  jQuery('#header-container .menu > ul > li').hover(function() {
  if (jQuery.browser.msie) {
  	jQuery('> a', this).stop(true, true).css({'opacity':1.0});
  	jQuery('> ul > li > a', this).stop(true, true).css({'opacity':1.0});
  }
  else{
    jQuery('> a', this).stop(true, true).animate({'opacity':1.0}, {queue:false, duration:100, easing:'easeOutCubic'});
    jQuery('> ul > li > a', this).stop(true, true).animate({'opacity':1.0}, {queue:false, duration:500, easing:'easeOutCubic'});
 }
    
  }, function() {
    jQuery('> a', this).stop(true, true).animate({'opacity':1.0}, {queue:false, duration:500, easing:'easeOutCubic'});
    jQuery('> ul > li > a', this).stop(true, true).animate({'opacity':0.7}, {queue:false, duration:500, easing:'easeOutCubic'});
  });
  
  /* Sub menu */
  if(jQuery('#header-container .menu > ul > li > ul').length > 0) {
    jQuery('#header').hover(function() {
      jQuery(this).animate({'height':(100 + hH) + 'px'}, {queue:false, duration:600, easing:'easeInOutExpo'});
    }, function() {
      jQuery(this).animate({'height':'42px'}, {queue:false, duration:600, easing:'easeInOutExpo'});
    });
    jQuery('#header-container .menu > ul > li > ul > li > a').css({'opacity':0.7});
    jQuery('#header-container .menu > ul > li > ul > li > a').hover(function() {
       jQuery(this).css({'opacity':0.5});
    }, function() {
       jQuery(this).css({'opacity':1.0});
    });
	
    /* Fix submenu width and height */
    var first = true;
    var hH = 0;
    jQuery.each(jQuery('#header-container .menu > ul > li'), function() {
      if(jQuery('ul', this).length == 0) {
        if(first) {
          jQuery('ul', this).css({'background':'none'});
          first = false; 
        } else {
          jQuery(this).append('<ul></ul>');
        }
      }
      jQuery.each(jQuery('ul', this), function() {
        if(first) {
          jQuery(this).css({'background':'none'});
          first = false; 
        }
        var m = jQuery(this).width();
        var h = 0;
        jQuery.each(jQuery(this).children(), function() {
          if(m < jQuery(this).width()) { m = jQuery(this).width(); }
        });
        jQuery('a', this).css({'width':(m - 30) + 'px'});
        jQuery.each(jQuery(this).children(), function() {
          h += jQuery(this).height();
        });
        if(hH < h) { hH = h; }
      });
      jQuery('#header-container .menu ul li ul').css({'height':(hH + 20) + 'px'});
    });
  };
  
});
