﻿/**
* jQuery Align Bottom
* Version 0.1 - 01/12/2008
* @author E-travel
*
* Resizes two or more boxes in order for them to have their bottom limit in the same position.
* How to use it: You select with jQuery the elements you need and then you call this function
**/
 
(function($){
    $.fn.alignbottom = function (options) {
        if (this.length == 0) return this;
        
        var biggest = -1,
            element = null;

        
        /* Find the "biggest" element and save it with its value */
        this.each(function() {
            $this = $(this);
            var value = $this.offset().top + $this.height();
            
            if (value > biggest) {
                biggest = value;
                element = this;
            }
        });
        
        
        
        /* Adjust all the elements */
        this.each(function() {
            /* Do not adjust the biggest element */
            if (element == this) return;
            
            $this = $(this);
            var height = $this.height()
            var value = $this.offset().top + height;
            var dif = biggest-value;
            
            /* Do not adjust elements that do not need fixing */
            if (dif == 0) return;
            
            /* Force CSS height */
            $this.height(height + dif);
        });
        
        /* jQuery chaining */ 
        return this;
    };
})(jQuery);