/*
* sameHeight jQuery Plugin
* by Andy Moser, Lifecom AG
* 17.08.2010
*
*/

jQuery.sameHeight = function(elements, setters, exceptions) {
	// Define some Variables
	var $selectors 		= jQuery.makeArray(elements),
		$selector 		= $selectors.join(", "),
		$collection		= jQuery($selector),
		$settersArray	= jQuery.makeArray(setters),
		$settersJoin	= $settersArray.join(", "),
		$selectorsToSet	= jQuery($settersJoin),
		//$exceptionsArray: items which should not be measured but also affected
		$exceptionsArray = jQuery.makeArray(exceptions), 
		$exceptionsArray = $exceptionsArray.join(", "),
		$exceptionsArray = jQuery($exceptionsArray),
		$max			= 0;
	
	// Get the maximal Height
	$collection.each(function() {
		if ($max < jQuery(this).outerHeight()) 
		{
			$max = jQuery(this).outerHeight();
		}
	});
	
	// Set the height for every Element
	$collection.each(function() {
		if (jQuery(this).outerHeight() != $max) {
			var paddingTop = jQuery(this).css("padding-top").split("px")[0];
			var paddingBottom = jQuery(this).css("padding-bottom").split("px")[0];
			jQuery(this).css("height", ($max-paddingTop-paddingBottom)+"px");
		}
	});
	
	$exceptionsArray.each(function() {
		if (jQuery(this).outerHeight() != $max) {
			var paddingTop = jQuery(this).css("padding-top").split("px")[0];
			var paddingBottom = jQuery(this).css("padding-bottom").split("px")[0];
			jQuery(this).css("height", ($max-paddingTop-paddingBottom)+"px");
		}
	});
				
	$selectorsToSet.each(function() {
		jQuery(this).css("height", $max+"px");
	});
}

