(function($) {

    var equalizeQueue = [];
    var documentReady = false;

    $(document).ready(function() {
        documentReady = true;
        runQueue();
    });

    $.fn.equalizeHeight = function() {
        if (!documentReady) {
            equalizeQueue.push(this);
            return;
        }

        equalizeHeight(this);
    };


    var runQueue = function() {
        for(var i = 0; i < equalizeQueue.length; i++) {
            equalizeHeight(equalizeQueue[i]);
        }
        equalizeQueue = [];
    };

    var equalizeHeight = function(node) {
        // find max height among the supplied elements
        var maxHeight = 0;
        node.each(function() {
            if ($(this).height() > maxHeight)
                maxHeight = $(this).height();
        });
        return node.css('height', maxHeight);
    };
})(jQuery);

