/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0, marginMax = 0;
		var margins = new Array();
		var i=0,j = 0;
  
		return this
			.css("min-height", "auto")
			.each(function(i) {
				height = Math.max(height, this.offsetHeight);
				if(car = $(this).css("margin-top").length){
					margins[i] = $(this).css("margin-top").substr(0,car-2);
					marginMax = Math.max(margins[i], marginMax);
				}
			})
			.css("min-height", height)
			.each(function(j) {
				var h = this.offsetHeight;
				var margintop = 0;
				margintop = margins[j];
				j++;
	
				//alert('h='+h+' height='+height+' margintop='+$(this).css("margin-top"));
				if (h > height) {
					$(this).css("min-height", height - (h - height) + (marginMax -margintop));
					if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
						$(this).css("height", height - (h - height) + (marginMax -margintop));
					}
				}
				else{
					$(this).css("min-height", height + (marginMax -margintop));
					if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
						$(this).css("height", height + (marginMax -margintop));
					}
				};
			});
			
	};
	
})(jQuery);

