/**
 *
 *
 * Created by: Becklyn GmbH, Jannik Zschiesche <jz@becklyn.com>
 * Date: 01.07.2011
 * Time: 6:52 PM
 */

$(
    function () {
        Index_Column_Height_Fix.init();
    }
);



var Index_Column_Height_Fix = {

    /**
     * The handler for the content block rows
     * @type jQuery
     */
    $rows: null,

    

    /**
     * Initializes the component
     */
    init: function () {
        this.$rows = $('#content-block-listing,.content-block-rows').find('.content-block-row');

        this._adjustHeightOfAllRows();
    },



    /**
     * Adjusts the height of all rows
     */
    _adjustHeightOfAllRows: function () {

        var self = this;
        this.$rows.each(
            function (index, element) {
                self._adjustHeightOfRow( $(element) );
            }
        );
    },



    /**
     * Adjusts the height of a single row
     * @param $row jQuery
     */
    _adjustHeightOfRow: function ($row) {
        var maximumHeight = this._getMaximumHeightOfRow($row);
        $row.find('.content-block .content p').css("height", maximumHeight);
    },



    /**
     * Returns the maximum height of a row
     * @param $row int
     */
    _getMaximumHeightOfRow: function ($row) {

        var maximumHeight = 0;

        $row.find('.content-block .content p').each(
            function (index, element) {
                maximumHeight = Math.max(maximumHeight, $(element).height());
            }
        );

        return maximumHeight;
    }

};
