/* 
   equalHeights plugin.

   This equalHeights plugin takes a set of elements, and works out
   the max height, setting the height of each subsequent element to
   the max.
   
   eg: $('div').equalHeights();
*/

(function($) {
  $.fn.equalHeights = function(options) {
    var opts = $.extend({}, $.fn.equalHeights.defaults, options);
        
    /* Work out the highest .height(). */
    var heightArr = new Array();
    var $items = this;
    function max(array){
        return Math.max.apply( Math, array );
    };
    
    if ($items.length == 0) return;
    $items.each(function(i){ 
      
      var $item = $(this);
      $(this).css({
        minHeight : 0,
        height : "auto"
      });
      heightArr[i] = $item.height();
      
      if (i == $items.length - 1) {
        var maxHeight = max(heightArr);
        $items.each(function(){ $(this).height(maxHeight); });
        return $items;
      }
    });
  }
  $.fn.equalHeights.defaults = {};
})(jQuery);