$(window).load(function() {

	function megaHoverOver(){
		$(this).find(".sub").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(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});

		} else { //If row does not exist...

			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});

		}
	}

	function megaHoverOut(){ 
	  $(this).find(".sub").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: 200, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	var col1h = $("#feature1").height();
	var col2h = $("#feature2").height();
	var col3h = $("#feature3").height();
	
	var biggest = -1;
	
	if ((col1h > col2h) && (col1h > col3h)) {
		biggest = 1;
	}
	if ((col2h > col1h) & (col2h > col3h)) {
		biggest = 2;
	}
	if ((col3h > col1h) & (col3h > col2h)) {
		biggest = 3;
	}

	if (biggest == 1) {
		$("#feature2").height(col1h);
		$("#feature3").height(col1h);
	} else if (biggest == 2) {
		$("#feature1").height(col2h);
		$("#feature3").height(col2h);
	} else {
		$("#feature1").height(col3h);
		$("#feature2").height(col3h);
	}


	$("ul#menu li .sub").css({'opacity':'0'});
	$("ul#menu li").hoverIntent(config);

	$( "#accordion" ).accordion({
		collapsible: true,
		autoHeight: false, 
		active: false
	});
	
	
resizeBlocks();
	
});

function resizeBlocks() {
	var biggestcontentblock = 0;
	$("div.singleblock").each(function(index) {
		if ($(this).height() > biggestcontentblock)
			biggestcontentblock = $(this).height();
	});
	$("div.singleblock").each(function(index) {
		$(this).height(biggestcontentblock);
	});
}
