
	
	$( document ).ready( function(){
	$('.mainNav li').hover(
		function(){
			
			//var two = $(this).find('li:first');
			
			$(this).addClass('hoverOn');
		
			var sub2 = $(this).find('.megaSub');
			if( sub2.length == 0 ) return;
			
			sub2.show();
			
			//$(two).removeClass('current');
			
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul.main").each(function() {					
					rowWidth += $(this).width() + 18; 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".megaSub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			//$(this).find(".megaSub").css({'width' : 580});
			$(this).find(".megaSub").css({'width' : rowWidth});

			$(this).find(".megaSub2").css({'width' : 200});
		}
			
			

			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hoverOn');
			var sub2 = $(this).find('.megaSub');
			sub2.hide();
		 	$(this).removeClass('hover');
		}
	);
});






