(function($){

	$.fn.equalizeHeights = function() {
		var opt = {};
		var height, outerHeight, tallest;

		// extend our default options with anything passed in by user
		$.extend(opt, $.fn.equalizeHeights.defaults, arguments[0] || {});

		this.each(function(){

			// our extended element
			var el = $(this);
			if(!height) {
				outerHeight = el.outerHeight(opt.includeMargin);
				height		= el.height();
			} else{ 
				
				if((el.outerHeight(opt.includeMargin) > height)) {
					outerHeight = el.outerHeight(opt.includeMargin);
					height = el.height();
					tallest = el;
				}
				
			}
		});
		
		return this.each(function(){
			if(tallest.get()[0] != this) {
				var finalHeight = height + opt.offset;
				if(!opt.setChildren) {
					$(this).height(finalHeight);
				} else {
					var delta = finalHeight - $(this).height();
					var child = $(this).find(opt.target);
					child.height(child.height() + delta + opt.offset);
				}
			}
		});
				
	};
	
	// Default options for the plugin.
	$.fn.equalizeHeights.defaults = {
		includeMargin: false,
		setChildren: false,
		target: ">:last-child",
		offset: 0
	};
	
})(jQuery);
