jQuery.fn.equalHeights = function(options) { var defaults = { perLine : false }; options = $.extend(defaults, options); if (options.perLine) { var count_items = this.size(), items_line = new Array(), items = this, round = Math.round(parseInt(count_items, 0) / parseInt(options.perLine, 0)), steps = (parseInt(count_items, 0) / parseInt(options.perLine, 0)) > parseInt(round, 0) ? parseInt(round, 0) + 1 : round; for (var i = 0; i < parseInt(steps, 0); i++) { var start = i * parseInt(options.perLine, 0); items_line[i] = new Array(); for (var j = 0; j < parseInt(options.perLine, 0); j++) { if (items[j + parseInt(start, 0)] != undefined) items_line[i].push(items[j + parseInt(start, 0)]); } } $.each(items_line, function(ind, val){ var array = new Array (); $.each(val, function() { array.push(jQuery(this).height()); }); var max = Math.max.apply(null, array); $.each(val, function(index, value) { $(this).css('height', max); }); }); } else { return this.height(Math.max.apply(null, this.map(function() { return jQuery(this).height() }).get() )); } };