/*
 * jQuery Equalize Heights Plugin
 * Author: Andres Diez
 * Comments: This plugin takes padding and borders into account
 */

(function(jQuery){

    $.fn.equalizeHeights = function() {
        var that = this;

        // Postpone execution so that we can measure sizes AFTER webfonts are loaded
        $(window).load(function() {
            // set var
            var maxHeight = 0;
            var currentInnerHeight = 0;
            var currentOuterHeight = 0;
            var currentDifference = 0;

            // get the greatest outerheight and save it before doing anything else
            that.each(function() {
                var $this = $(this);
                if ($this.outerHeight() > maxHeight) {
                    maxHeight = $this.outerHeight();
                }
            });
    
            that.each(function() {
                var $this = $(this);
                // do not work on the tallest element
                if ($this.outerHeight() < maxHeight) {
                    // get current elements inner height & outer height
                    currentInnerHeight = $this.height();
                    currentOuterHeight = $this.outerHeight();
                    // calculate difference between current outer height and max outer height
                    currentDifference = maxHeight - currentOuterHeight;
                    // add that to the inner height and set it as CSS min-height
                    $this.css("min-height", currentInnerHeight + currentDifference);
                }
            });

        });
    }

})(jQuery);















