jQuery().ready(function() {
	
	function megaHoverOver() {
		jQuery(this).find(".subNavigation").stop().fadeTo('fast', 1).show();
						
		(function(jQuery) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
							
				jQuery(this).find("ul").each(function() {					
					rowWidth += jQuery(this).width(); 
				});	
			};
		})(jQuery); 
					
		if(jQuery(this).find(".subRow").length > 0 ) { 
			var biggestRow = 0;	
						
			jQuery(this).find(".subRow").each(function() {							   
				jQuery(this).calcSubWidth();
				
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
					
			jQuery(this).find(".subNavigation").css({'width' :biggestRow});
			jQuery(this).find(".subRow:last").css({'margin':'0'});
		} else { 						
			jQuery(this).calcSubWidth();
			jQuery(this).find(".subNavigation").css({'width' : rowWidth});
		}
	}
				
	function megaHoverOut(){ 
		jQuery(this).find(".subNavigation").stop().fadeTo('fast', 0, function() {
			jQuery(this).hide(); 
		});
	}
						
	var config = {    
		sensitivity: 2, 
		interval: 100,    
		over: megaHoverOver,     
		timeout: 100,  
		out: megaHoverOut     
	};
			
	jQuery("#navigation ul li .subNavigation").css({'opacity':'0'});
	jQuery("#navigation ul li").hoverIntent(config);			
});
