// Script för att balansera kolumnerna #aside-left, #content och #sidebar.
jQuery(function($) {
	var $lastModules = $('ul.startlist.big li.grid_4').add('#aside-left .module:last').add('#sidebar .module:last').add('#content')
	.not('#content.grid_12').not('#content.no-border')//Ansokan,listvy
	.add('#content.no-border .module:last');//Listvy
	var newHeight = 0;
	var height = 0;
	var maxHeight = 0;
	var offsetTuple;

	$lastModules.each(function(ix, val) {
		offsetTuple = $(this).offset();
		var customOffset = ($(this).attr('id') == 'content') ? +40 : 0;
		height = offsetTuple.top + $(this).outerHeight() + customOffset;
		$(this).data('height', height);
		maxHeight = (height > maxHeight) ? height : maxHeight;
	});

	$lastModules.each(function(ix, val) {
		if ($(this).data('height') <= maxHeight) {
			newHeight = maxHeight - $(this).data('height') + $(this).outerHeight();
			newHeight = Math.ceil(newHeight);
			if(!$(this).hasClass('hfeed-entry'))
				$(this).height(newHeight);
		}
	});
});
