﻿(function ($) {   
    $.fn.extend({        
        equalHeight: function (options) {
            //set default height to 0 or auto
            var defaults = {
                height:null,
                minHeight: 0,
                maxHeight: null,
                liquidWidth:""               
            };
            //merge options
            options = $.extend(defaults, options);
            //cache the children (is this the parent or a group of elements)
            var children = (this.length > 1) ? this : this.children();             
            if(options.height !== null){
                //if specific height is set
                children.height(options.height);
            }else{
                //set the height to auto which releases the boxes heights
                children.css('height', 'auto');
                //loop though the elements and get their heights
                children.each(function () {            
                    //if bigger than the default set to default
                    if ($(this).height() > options.minHeight) options.minHeight= $(this).height();
                    //if maxheight is set
                    if(options.maxHeight !== null){
                        if(options.minHeight > options.maxHeight) options.minHeight= options.maxHeight;
                    }
                });
                //set the height on all the children
                $(this).css('width','100%');
                $(this).height(options.minHeight);
                children.height(options.minHeight);
                children.width('100%');
            }
            //return this so the jQuery chain is preserved
            return this;
        }
     });  
})(jQuery);
