jQuery.fn.pagination=function(h,a){a=jQuery.extend({items_per_page:10,num_display_entries:10,current_page:0,num_edge_entries:0,link_to:"#",prev_text:"Prev",next_text:"Next",ellipse_text:"...",prev_show_always:true,next_show_always:true,callback:function(){return false}},a||{});return this.each(function(){function o(){var b=Math.ceil(a.num_display_entries/2),c=Math.ceil(h/a.items_per_page),i=c-a.num_display_entries;return[d>b?Math.max(Math.min(d-b,i),0):0,d>b?Math.min(d+b,c):Math.min(a.num_display_entries,
c)]}function l(b,c){d=b;m();var i=a.callback(b,j);if(!i)if(c.stopPropagation)c.stopPropagation();else c.cancelBubble=true;return i}function m(){j.empty();var b=o(),c=Math.ceil(h/a.items_per_page),i=function(f){return function(g){return l(f,g)}},k=function(f,g){f=f<0?0:f<c?f:c-1;g=jQuery.extend({text:f+1,classes:""},g||{});var n=f==d?jQuery("<span class='current'>"+g.text+"</span>"):jQuery('<a href="javascript:;">'+g.text+"</a>").bind("click",i(f));g.classes&&n.addClass(g.classes);j.append(n)};if(a.prev_text&&
(d>0||a.prev_show_always))k(d-1,{text:a.prev_text,classes:"prev"});if(b[0]>0&&a.num_edge_entries>0){for(var p=Math.min(a.num_edge_entries,b[0]),e=0;e<p;e++)k(e);a.num_edge_entries<b[0]&&a.ellipse_text&&jQuery("<span>"+a.ellipse_text+"</span>").appendTo(j)}for(e=b[0];e<b[1];e++)k(e);if(b[1]<c&&a.num_edge_entries>0){c-a.num_edge_entries>b[1]&&a.ellipse_text&&jQuery("<span>"+a.ellipse_text+"</span>").appendTo(j);for(e=Math.max(c-a.num_edge_entries,b[1]);e<c;e++)k(e)}if(a.next_text&&(d<c-1||a.next_show_always))k(d+
1,{text:a.next_text,classes:"next"})}var d=a.current_page;h=!h||h<0?1:h;a.items_per_page=!a.items_per_page||a.items_per_page<0?1:a.items_per_page;var j=jQuery(this);this.selectPage=function(b){l(b)};this.prevPage=function(){if(d>0){l(d-1);return true}else return false};this.nextPage=function(){if(d<Math.ceil(h/a.items_per_page)-1){l(d+1);return true}else return false};m()})};
