﻿/// <reference path="../Plugins/jquery-1.3.2-vsdoc.js" />
Type.registerNamespace("Controls");

/*
V1.3 The pager control
/// Depends:
/// jquery-1.4.js
///	ui.core.js
/// ExtendJquery.js
/// MicrosoftAjax.js
*/
Controls.PageSize = function () {
}
Controls.PageSize.prototype = {
    _init: function () {
        $('.pageSize', this.element).live('click', $.createEventDelegate(this, this._PageSize));
        $(this.element).bind("refreshPager", $.createEventDelegate(this, this._Refresh));
        this.options.currentPageSize = 12;
        this.options.length = -1;
    },
    _Refresh: function (element, event, currentPage, noOfPages, currentPageSize, length) {
        this.options.length = length;
        this.Refresh(currentPageSize, length);
    },
    Refresh: function (currentPageSize, length) {
        if (typeof (currentPageSize) != "undefined") { this.options.currentPageSize = currentPageSize; };
        if (typeof (length) != "undefined") { length = this.options.length; }
        $('.pageSize', this.element).hide();
        $('.pageSize', this.element).removeClass(this.options.currentPageSizeClass);
        var currentPageSize = this.options.currentPageSize;
        var currentPageSizeClass = this.options.currentPageSizeClass;
        var currentIsSet = false;
        $('.pageSize', this.element).each(function () {
            if (($(this).data("pagesize") / 1) <= length) { //Math.round(length/12+0.5)*12
                $(this).show();
                if (currentPageSize == ($(this).data("pagesize") / 1) || (($(this).data("pagesize") / 1) == 0 && !currentIsSet)) {
                    $(this).addClass(currentPageSizeClass);
                    currentIsSet = true;
                }
            }
        });
    },

    _PageSize: function (element, event) {
        this._ChangePageSize($(element).data("pagesize") / 1);
    },
    _ChangePageSize: function (pageSize) {
        if (typeof (pageSize) == "undefined") {
            pageSize = this.options.currentPageSize;
        }
        else {
            this.options.currentPageSize = pageSize;
        }
        this.Refresh();
        $(this.options.parent).triggerHandler("changePageSize", [pageSize]);
    },
    defaults: {
        parent: "#productListItems", //path to the PageJSON plugin
        currentPageSizeClass: "current"
    }
}

Controls.PageSize.registerClass('Controls.PageSize', null, Sys.IDisposable);
$.registerAsWidget(Controls.PageSize);





