/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(params) {
		var options = jQuery.extend({
			maxHeight: 0,
			minHeight: 0,
			useOuterHeight: true,
			includeMargin: false
		}, params);
		
		var tallest = (options.minHeight) ? options.minHeight : 0;
		var height = tallest;

		this.each(function() {
			height = options.useOuterHeight ? $(this).outerHeight( options.includeMargin ) : $(this).height();
			if( height > tallest) {
				tallest = height;
			}
		});
		if((options.maxHeight) && tallest > options.maxHeight) tallest = options.maxHeight;
		return this.each(function() {
			var newHeight = (options.useOuterHeight) ? tallest - ($(this).outerHeight(options.includeMargin) - $(this).height()) : tallest;
			
			/* Sticky problem here.  Using 'min-height' doesn't work in IE6, and adding "IE7/8.js" for min-height support breaks other things.
			 * Using jQuery.height() instead (which was used previously) causes weird reflow issues in all browsers if used in conjunction
			 * with dynamically expanding content (e.g. inserting error messages into a document dynamically).
			 */
			$(this).css('min-height', newHeight + 'px');
		});
	}
})(jQuery);
