﻿jQuery.fn.equalHeight = function(options, optionalCallback) {
    var $ = jQuery;
    if (options > 0) { options = { height: options }; }
    var defaults = { height: null }
    var options = jQuery.extend(defaults, options);
    var maxHeight = -1;
    var matches = this;
    return this.each(function(index) {
        setTimeout(function() {  // timeout is for safai bug when dom not ready in time
            if (options.height === null) {
                if (maxHeight < 0) { matches.each(function(i) { maxHeight = ($(this).height() > maxHeight) ? $(this).height() : maxHeight; }); }
                matches.height(maxHeight);
            } else { matches.height(options.height); }
            if (index == matches.length - 1 && optionalCallback) {
                optionalCallback();
            }
        }, 50);
    });
};
