/*!
 * jQuery alignHeightsInRow Plugin v1.0.0
 * http://www.billiton.de
 *
 * Copyright (c) 2009 Sebastian Busch,
 *                    billiton internet services GmbH
 *                    http://www.billiton.de
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.
 *
 * $Date: 2009-04-04 13:44:43 +0200 (Sa, 04 Apr 2009) $
 * $Revision: 7428 $
 */
jQuery.fn.alignHeightsInRow = function()
{
    function alignHeights(group)
    {
        var maxHeight = null;
        jQuery.each(group, function()
        {
            var height = jQuery(this).height();
            if ((maxHeight === null) || (height > maxHeight))
            {
                maxHeight = height;
            }
        });
        jQuery(group).height(maxHeight);
    }

    var group = [];
    var lastTop = null;
    jQuery.each(this, function()
    {
        var top = jQuery(this).offset().top;

        if ((lastTop !== null) && (top != lastTop))
        {
            alignHeights(group);
            group = [];
            top = jQuery(this).offset().top;
        }
        group.push(this);

        lastTop = top;
    });

    if (group.length)
    {
       alignHeights(group);
    }

    return this;
}

