/* ------------------------------------------------------------------------
	Class: equalHeights
	Use: To Set the height of all selected elements to be the 
	     same height
	Author: Martin Poucher
	Company: Magico.ie
	Version: 1.0
	Created: 26th Feb 2009
------------------------------------------------------------------------- */

$.fn.equalHeights = function(options) {
    settings = $.extend({
        increaseHeight: 0
    }, options);

    /* This resets the height on each box. This is needed because all the heights may
       may be the same due to this plugin being called before */
    $(this).css({'height': 'auto'});
    
    var maxHeight = 0;
    $.each($(this), function() {
        if(this.clientHeight > maxHeight) maxHeight = this.clientHeight;
    });
    
    /* Checking if this selector was found on the page. If not, skip this code because if an element isn't found, it isn't assigned a
       padding value. If you try to get the padding value for a non existant element, an error will be thrown */
    if (maxHeight > 0) {
        var elementPaddingTop = $(this).css('padding-top').replace('px', '');
        var elementPaddingBottom = $(this).css('padding-bottom').replace('px', '');
        var elementMarginTop = $(this).css('margin-top').replace('px', '');
        var elementMarginBottom = $(this).css('margin-bottom').replace('px', '');
        maxHeight = maxHeight - elementPaddingTop - elementPaddingBottom - elementMarginTop - elementMarginBottom +
                    settings.increaseHeight;
        
        $(this).css({'height': maxHeight});
    }
};