(function(n){n.PaginationCalculator=function(n,t){this.maxentries=n,this.opts=t},n.extend(n.PaginationCalculator.prototype,{numPages:function(){return Math.ceil(this.maxentries/this.opts.items_per_page)},getInterval:function(n){var t=Math.floor(this.opts.num_display_entries/2),i=this.numPages(),r=i-this.opts.num_display_entries,u=n>t?Math.max(Math.min(n-t,r),0):0,f=n>t?Math.min(n+t+this.opts.num_display_entries%2,i):Math.min(this.opts.num_display_entries,i);return{start:u,end:f}}}),n.PaginationRenderers={},n.PaginationRenderers.defaultRenderer=function(t,i){this.maxentries=t,this.opts=i,this.pc=new n.PaginationCalculator(t,i)},n.extend(n.PaginationRenderers.defaultRenderer.prototype,{createLink:function(t,i,r){var u,f=this.pc.numPages();return t=t<0?0:t<f?t:f-1,r=n.extend({text:t+1,classes:""},r||{}),u=t==i?n("<span class='current'>"+r.text+"<\/span>"):n("<a>"+r.text+"<\/a>").attr("href",this.opts.link_to.replace(/__id__/,t)),r.classes&&u.addClass(r.classes),u.data("page_id",t),u},appendRange:function(n,t,i,r,u){for(var f=i;f<r;f++)this.createLink(f,t,u).appendTo(n)},getLinks:function(t,i){var e,o,u=this.pc.getInterval(t),f=this.pc.numPages(),r=n("<div class='pagination'><\/div>");return this.opts.prev_text&&(t>0||this.opts.prev_show_always)&&r.append(this.createLink(t-1,t,{text:this.opts.prev_text,classes:this.opts.prev_class})),u.start>0&&this.opts.num_edge_entries>0&&(o=Math.min(this.opts.num_edge_entries,u.start),this.appendRange(r,t,0,o,{classes:"sp"}),this.opts.num_edge_entries<u.start&&this.opts.ellipse_text&&jQuery("<span>"+this.opts.ellipse_text+"<\/span>").appendTo(r)),this.appendRange(r,t,u.start,u.end),u.end<f&&this.opts.num_edge_entries>0&&(f-this.opts.num_edge_entries>u.end&&this.opts.ellipse_text&&jQuery("<span>"+this.opts.ellipse_text+"<\/span>").appendTo(r),e=Math.max(f-this.opts.num_edge_entries,u.end),this.appendRange(r,t,e,f,{classes:"ep"})),this.opts.next_text&&(t<f-1||this.opts.next_show_always)&&r.append(this.createLink(t+1,t,{text:this.opts.next_text,classes:this.opts.next_class})),n("a",r).click(i),r}}),n.fn.pagination=function(t,i){function h(t){var r=n(t.target).data("page_id"),i=e(r);return i||t.stopPropagation(),i}function e(n){r.data("current_page",n),u=o.getLinks(n,h),r.empty(),u.appendTo(r);return i.callback(n,r)}var r,o,u,f,c,s;if(i=jQuery.extend({items_per_page:10,num_display_entries:11,current_page:0,num_edge_entries:0,link_to:"#",prev_text:"Prev",prev_class:"prev",next_text:"Next",next_class:"next",ellipse_text:"...",prev_show_always:!0,next_show_always:!0,renderer:"defaultRenderer",callback:function(){return!1}},i||{}),r=this,f=i.current_page,r.data("current_page",f),t=!t||t<0?1:t,i.items_per_page=!i.items_per_page||i.items_per_page<0?1:i.items_per_page,!n.PaginationRenderers[i.renderer])throw new ReferenceError("Pagination renderer '"+i.renderer+"' was not found in jQuery.PaginationRenderers object.");o=new n.PaginationRenderers[i.renderer](t,i),c=new n.PaginationCalculator(t,i),s=c.numPages(),r.bind("setPage",{numPages:s},function(n,t){if(t>=0&&t<n.data.numPages)return e(t),!1}),r.bind("prevPage",function(){var t=n(this).data("current_page");return t>0&&e(t-1),!1}),r.bind("nextPage",{numPages:s},function(t){var i=n(this).data("current_page");return i<t.data.numPages-1&&e(i+1),!1}),u=o.getLinks(f,h),r.empty(),u.appendTo(r),i.callback(f,r)}})(jQuery);