$(function(){
	
	// set each column height to the tallest
	$('.mega').each(function(index) {
	  var greatest_height = 0;
	  
		var cols = $(this).find('.col');
		cols.each(function(index) {
			
		  if($(this).height() > greatest_height){
				greatest_height = $(this).height();
				
		}
		});
		cols.height(greatest_height);
	});
	
	$('.megapanel').css({'display':'none','visibility':'visible'});
	
	// horizontally center top level menu items 
	var mega_width = 0;
	var mega_count = $('li.mega').length;
	$('li.mega').each(function(index) {
	  mega_width += $(this).width();
	});
	var padding = ((920 - mega_width) / 2) / mega_count;
	$('li.mega > h2 a').css({'paddingLeft': padding, 'paddingRight': padding});
	$('li.mega').css('visibility', 'visible');
	// attach "last" class to last li.mega
	$('li.mega:last').css('background', 'none');
	
	// if panel extends past 940px container, set it right = -0
	$('.megapanel').each(function(index) {
		// check if css property "left" is set, if not get the position
		var position = ($(this).css('left') == 'auto') ? $(this).parent().position().left : $(this).css('left');
		// get the width
		var panel_width = $(this).width();
		// get the total span of the panel
		var total_span = position + panel_width;
		// if the panel extends, right align
		if(total_span > 930){
			$(this).css('right', 0);
		}
	});
	
});
