/**
 * 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.
 * 
 */

tallest = [];

(function($) {
	$.fn.equalHeights = function() {

		this.each(function() {
			line=$(this).attr('line');
			if(tallest[line]==undefined) tallest[line]=0; 
			if($(this).height() > tallest[line]) {
				tallest[line] = $(this).height();
			}
		});
		return this.each(function() {
//var valign = $(this).parent('td').attr('valign');
			var valign = $(this).attr('valign');
//alert($(this).parent('td').attr('valign'));
			var new_h = tallest[$(this).attr('line')];
			if(valign=='bottom') {
				var h = $(this).height();
				var p = parseInt($(this).css("padding-top"));
				var m = new_h-h;
				new_h -= m;
				$(this).css("padding-top",(m+p)+'px');
			} else if(valign!='top') {
				var h = $(this).height();
				var p = parseInt($(this).css("padding-top"));
				var m=Math.floor((new_h-h)/2);
				new_h-=m;
				$(this).css("padding-top",(m+p)+'px');
			}
			$(this).height(new_h).css("overflow","auto");
			//$(this).height(new_h).css("overflow","hidden");
//$(this).html($(this).html()+'H='+new_h+' h='+h+' pad='+m);
		});
	}
})(jQuery);
