/*
 * http://plugins.jquery.com/project/equalizeCols
 * 
 * @version 1.1 JSLint verified
 */

(function ($) {
	
	$.fn.equalizeCols = function (children) {

		var child = [];
	
		if (children) {
			child = children.split(",");
		}
	
		var maxH = 0;
    
		this.each(
			function (i) {
				if (this.offsetHeight > maxH) {
					maxH = this.offsetHeight;
				}
			}
		/*).css("height", "auto").each(*/
		).each(
			function (i) {
				var gap = maxH - this.offsetHeight;
				if (gap > 0) {	
					var t = document.createElement('div');
					$(t).attr("class", "fill").css("height", gap + "px");
					if (child.length > i) {
						$(this).find(child[i]).children(':last-child').after(t);
					} 
					else {
						$(this).children(':last-child').after(t);
					}
				}
			}  
		);
    
	};
	
	$.extend({equalizeCols: {
		afterPagination : function (opts) {
			//show element with hidden visibility, equalize heights and hide it again
			var divs = opts.items.slice(opts.from, opts.to); //get the divs for the current page
			divs.css({visibility: 'hidden'});
			divs.show();
			var rem = divs.find("div.fill").remove(); //remove any fills from previous equalizecols calls
			$(opts.equalizecols, divs).equalizeCols();	
			divs.hide();
			
			// Try to re-tabulate to re-adjust the height of the tab incase we have grown in size
			var index = opts.el.parents(".sections").children().index(opts.el.get(0));
			var sections = opts.el.parents(".sections");
			var div = sections.children("div.tabContent:eq(" + index + ")");

			// Resize the tab
			$.eatab.resizeAndShow(sections, div, opts);

			// Show the divs
			divs.css({visibility: 'visible'});
		}
	}});
	
	
	
})(jQuery);