/*
 * JEqualize 0.1.2
 * By Eugene Poltorakov (http://poltorakov.com)
 * Copyright (c) 2009 eugene poltorakov
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
(function($){
  $.fn.equalize = function(options) {
    var settings = $.extend({
        step: 2,
        css : false, //add this properies for all processed item
        addClass : false //add class to each processed element
      }, options
    );
    var that = this;
    var items = [];
    this.each(function(){
      $(this).height('auto');
      var line  = Math.floor($(that).index(this)/settings.step) ;
      var height = ($.browser.msie ? $(this)[0].offsetHeight : $(this).height());
      items[line] = items[line] ? Math.max(items[line], height) : height;
    });
    this.each(function(){
      var line  = Math.floor($(that).index(this)/settings.step);
      $(this).height(items[line] + 'px');
    });
    if (settings.addClass) {
      this.addClass(settings.addClass);
    }
    if (settings.css) {
      for(i in settings.css) {
        this.css(i, settings.css[i]);
      }
    }
  };
})(jQuery);

