/// class ProspectDirector.Web.UI.Utilities.Kendo.Grid.Fill

ProspectDirector.Web.UI.Utilities.Kendo.Grid.Fill = Class.extend({

    init: function (options) {

        this.options = $.extend({
            selector: null,
            useAvailableSpace: false
        }, options);

    },

    get_grid: function () {
        return $(this.options.selector);
    },

    get_content: function () {
        return this.get_grid().find(".k-grid-content");
    },

    get_nonContent: function () {
        return this.get_grid().children().not(".k-grid-content");
    },

    size: function () {

        var height = this.getAvailableSpace(),
            nonContentHeight = 0;

        this.get_nonContent().each(function () {
            nonContentHeight += $(this).outerHeight(true);
        });

        this.get_content().height(height - nonContentHeight);

    },

    getAvailableSpace: function () {

        var height = 0,
            grid = this.get_grid();

        if (this.options.useAvailableSpace) {

            height = this.get_grid().parent().outerHeight(true);

            this.get_grid().parent().children().each(function (index, element) {
                if (!$(element).is(grid)) {
                    height = height - $(element).outerHeight(true);
                }
            });

        }
        else {
            height = this.get_grid().innerHeight();
        }

        return (height < 0) ? 0 : height;

    }

});