/*
	evenColumn — A jQuery Plugin
	Author: Matt Wozniak
	
	A simple plugin to even out columns on a page.
*/


(function($){
	var rows = {};
	$.fn.extend({
		//seperate into rows
		evenColumn: function(){			
			$(this).each(function(){
				var classes = $(this).attr('class');
				var rowName = null;
				if(classes)
					regexResult = classes.match(/row_[a-z]/);
				if(regexResult) {
					rowName = regexResult[0];
					if(rows[rowName])
						rows[rowName].push(this);
					else
						rows[rowName] = [this];
				}
			});
			$.each(rows,function(){
				var tallest;
				
				$.each(this,function(){
					if(!tallest)
						tallest = this;
					else if($(this).height()+$(this).offset().top > $(tallest).height()+$(tallest).offset().top)
						tallest = this;
				});
				$.each(this,function(){
					var myH,myO,tallH,tallO;
					myH = $(this).height();
					myO = $(this).offset().top;
					tallH = $(tallest).height();
					tallO = $(tallest).offset().top;

					if(this!=tallest) {
						$(this).css('min-height',myH+(tallH+tallO-myH-myO)+'px');
					}
				});
			});
			return this;
		}
	});
})(jQuery)

$(document).ready(function(){
	$('.border').evenColumn();
});
