/** 
@fileOverview Common extensions to jQuery
*/

(function ($) {
	$.extend($.fn, {

		/**
		Return or set the minimum height of an element
		@param {Number} [height] Set the minimum height to this value
		@memberOf $.fn
		*/
		minHeight: function(height) {
			// Explorer versions prior to IE7 needs to have height instead of min-height
			var type = ($.browser.msie && parseInt($.browser.version, 10) < 7)	? "height" : "min-height";
			if (height == undefined) {
				// Get min-height for the first element
				return this.css(type);
			} else {
				// Set the min-height on all elements (default to pixels if value is unitless)
				this.css(type, height.toString().match(/^\d+$/) ? height + "px" : height);
				return this;
			}
		},
		/**
		Return the height of the tallets matched element
		@memberOf $.fn
		*/
		getHighestHeight: function () {
			var maxHeight = 0;
			// Get the height of the highest element
			this.each(function() {
				var el = $(this), height;
				el.minHeight(0);
				height = el.outerHeight();
				if (height > maxHeight) {
					maxHeight = height;
				}
			});
			return maxHeight;
		},
		/**
		Justifies the heights of a bunch of elements to match the highest one
		@memberOf $.fn
		*/
		justify: function() {
			var maxHeight = this.getHighestHeight();
			// Set min-height for all elements
			this.each(function () {
				var el = $(this);
				el.minHeight(el.height() + maxHeight - el.outerHeight());
			});
			return this;
		}

	});
})(jQuery);

