﻿Type.registerNamespace("PalmspringControls");

PalmspringControls.PageSize = function() {
    ///<Summary>    
    ///</Summary>
   
    this.CurrentPageSize = 0;
    this.PageSizeId = '';
    this.PageSizeTemplateId = '';
    PalmspringControls.PageSize.ObjectArgument.apply(this, arguments);
}

PalmspringControls.PageSize.ObjectArgument = function(options) {
    this.PageSize = options.PageSize;
    this.GridControlId = options.GridControlId;
    this.Template = options.Template;
    this.$ps = $("#divPageSize" , $("#" + options.GridControlId));
    this.OnPageSizeChange = options.OnPageSizeChange;
}

PalmspringControls.PageSize.prototype = {
    initialize: function() {
        //var $pager = $("#" + this.PagerId);
        var psTemplate = this.Template;

        if (!IsEmpty(this.$ps)) {
            $(this.$ps).text('');
            $(psTemplate).bindTo(PageSizes, { appendTo: $(this.$ps) });
        }
        else {
            $ps.css("display", "none");
        }

        if (typeof this.OnPageSizeChange == 'function') {
            var func = this.OnPageSizeChange;
            var currFunc = this.SetCurrent;
            var ps = this.$ps;
            //  `$("ul", this.$ps).text('');
            $("ul", this.$ps).find("a").each(function() {
                $(this).bind("click", function() {
                    currFunc.call(this, this, ps);
                    func.call(this, $(this).attr("Size"));
                    return false;
                });
            });
        }

        this.SetCurrent(this.$ps.find("a[Size=" + this.PageSize + "]"), this.$ps);
    },
    SetCurrent: function(aLink, pagesize) {
		$("li", $(pagesize)).removeClass("pagerCurrentBtm");
        $(aLink).parent().addClass("pagerCurrentBtm");

    }
}

PalmspringControls.PageSize.registerClass("PalmspringControls.PageSize", null, Sys.IDisposable);
