﻿(function($) {
    $.fn.Paging = function(options) {
        var opts = $.extend({}, $.fn.DataBind.defaults, options);

        return this.each(function() {
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
            var intPages;
            var arrPages = new Array();
            var intIndex = 0;

            intPages = o.RecordCount / o.PageSize;

            if (intPages > 1 && o.RecordCount % o.PageSize > 0) {
                intPages = parseInt(intPages + 1);
            } else {
                if (intPages <= 1) {
                    intPages = 1;
                }
            }

            for (intIndex = 0; intIndex <= intPages - 1; intIndex++) {
                arrPages[intIndex] = intIndex + 1;
            }

            $(this).DataBind({
                Data: arrPages,
                ClearContent: true,
                BindItem: o.BindItem
            });

        });
    };

    $.fn.Paging.Defaults = {
        PageSize: 25,
        RecordCount: 0,
        BindItem: ''
    };

})(jQuery);
