$(document).ready(function() {
	

	function megaHoverOver(){
		
			$(this).find(".A_subA").stop().fadeTo('fast', 1).show();
			$(this).find(".A_subB").stop().fadeTo('fast', 1).show();
			$(this).find(".A_subC").stop().fadeTo('fast', 1).show();
			$(this).find(".A_subD").stop().fadeTo('fast', 1).show();
			$(this).find(".B_subA").stop().fadeTo('fast', 1).show();
			$(this).find(".B_subB").stop().fadeTo('fast', 1).show();
			$(this).find(".B_subC").stop().fadeTo('fast', 1).show();
			$(this).find(".B_subD").stop().fadeTo('fast', 1).show();
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(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(".A_subA").css({'width' :biggestRow});
			$(this).find(".A_subB").css({'width' :biggestRow});
			$(this).find(".A_subC").css({'width' :biggestRow});
			$(this).find(".A_subD").css({'width' :biggestRow});
			$(this).find(".B_subA").css({'width' :biggestRow});
			$(this).find(".B_subB").css({'width' :biggestRow});
			$(this).find(".B_subC").css({'width' :biggestRow});
			$(this).find(".B_subD").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
	
			$(this).find(".A_subA").css({'width' : rowWidth});
			$(this).find(".A_subB").css({'width' : rowWidth});
			$(this).find(".A_subC").css({'width' : rowWidth});
			$(this).find(".A_subD").css({'width' : rowWidth});
			$(this).find(".B_subA").css({'width' : rowWidth});
			$(this).find(".B_subB").css({'width' : rowWidth});
			$(this).find(".B_subC").css({'width' : rowWidth});
			$(this).find(".B_subD").css({'width' : rowWidth});
			
			
		}
	}
	
	function megaHoverOut(){ 
		   $(this).find(".A_subA").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); });
		   $(this).find(".A_subB").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); });
		   $(this).find(".A_subC").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); });
		   $(this).find(".A_subD").stop().fadeTo('fast', 0, function() {
		  $(this).hide();  });
	 		$(this).find(".B_subA").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); });
		   $(this).find(".B_subB").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); });
		   $(this).find(".B_subC").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); });
		   $(this).find(".B_subD").stop().fadeTo('fast', 0, function() {
		  $(this).hide();  });
	  
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};


	$("ul#topnav li .A_subA").css({'opacity':'0'});
	$("ul#topnav li .A_subB").css({'opacity':'0'});
	$("ul#topnav li .A_subC").css({'opacity':'0'});
	$("ul#topnav li .A_subD").css({'opacity':'0'});
	$("ul#topnav li .B_subA").css({'opacity':'0'});
	$("ul#topnav li .B_subB").css({'opacity':'0'});
	$("ul#topnav li .B_subC").css({'opacity':'0'});
	$("ul#topnav li .B_subD").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	

});

$(function() {
	var zIndexNumber = 10000;
	$('*').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});

$(function() {
$("ul#topnav li a.about").css({'zIndex':'0'});
	$("ul#topnav li a.wire").css({'zIndex':'0'});
});

