(function($){$.fn.jpaging=function(options){var b="",options=$.extend({items_on_page:10,pages_step:5,all_items_num:0,callback:b},options);return this.each(function(){var e="page",d="current",c=false,a=this,hndl=a;a.get_pages_num=function(){return eval(Math.ceil(options.all_items_num/options.items_on_page))};a.div=$(a);a.div.html('<div class="panel"></div><div class="info"></div>');a.div.addClass("jpaging");a.panel=a.div.find("div.panel");a.info=a.div.find("div.info");a.current_page=1;a.pages_num=a.get_pages_num();a.start_index=0;a.end_index=0;a.prev_pages_num=0;a.prev_start_page=1;a.next_pages_num=0;a.next_last_page=1;a.description=b;a.first_arrow_visible=c;a.prev_arrow_visible=c;a.last_arrow_visible=c;a.next_arrow_visible=c;a.first=b;a.last=b;a.next=b;a.last=b;a.getPrevIndex=function(){return hndl.current_page<=1?1:hndl.current_page-1};a.getNextIndex=function(){return hndl.current_page>=hndl.pages_num?hndl.pages_num:eval(hndl.current_page)+1};a.get_link=function(d,c,a,b){return'<a href="#" title="'+b+'" class="'+a+'">'+c+"</a>"};a.update_class=function(){hndl.div.find("a").removeClass(d);hndl.div.find("a.page"+hndl.current_page).addClass(d)};a.set_visibility=function(){var c="hidden",b="visible",a="visibility";hndl.prev.removeClass().addClass(e+hndl.getPrevIndex()+" prev");hndl.next.removeClass().addClass(e+hndl.getNextIndex()+" next");if(hndl.first_arrow_visible)hndl.first.css(a,b);else hndl.first.css(a,c);if(hndl.prev_arrow_visible)hndl.prev.css(a,b);else hndl.prev.css(a,c);if(hndl.next_arrow_visible)hndl.next.css(a,b);else hndl.next.css(a,c);if(hndl.last_arrow_visible)hndl.last.css(a,b);else hndl.last.css(a,c)};a.draw_paging=function(){hndl.panel.html(b);hndl.info.html(b);if(hndl.pages_num>1){hndl.panel.append(hndl.get_link(1,"&laquo;","page1 first","First page"));hndl.first=hndl.panel.find(".first");hndl.panel.append(hndl.get_link(hndl.getPrevIndex(),"&lt;",e+hndl.getPrevIndex()+" prev","Previous page"));hndl.prev=hndl.panel.find(".prev");for(var i=hndl.prev_start_page;i<eval(hndl.prev_start_page)+hndl.prev_pages_num;i++)hndl.panel.append(hndl.get_link(i,i,"page"+i,"Page "+i));hndl.panel.append(hndl.get_link(hndl.current_page,hndl.current_page,"page"+hndl.current_page+" current","Page "+i));for(var i=eval(hndl.current_page)+1;i<=eval(hndl.current_page)+hndl.next_pages_num;i++)hndl.panel.append(hndl.get_link(i,i,"page"+i,"Page "+i));hndl.panel.append(hndl.get_link(hndl.getNextIndex(),"&gt;","page"+hndl.getNextIndex()+" next","Next page"));hndl.next=hndl.panel.find(".next");hndl.panel.append(hndl.get_link(hndl.pages_num,"&raquo;","page"+hndl.pages_num+" last","Last page"));hndl.last=hndl.panel.find(".last");hndl.info.append(hndl.description);hndl.panel.find("a").unbind("click").click(function(){var a=$.trim($(this).attr("class").replace(e,b).replace(d,b).replace("next",b).replace("prev",b).replace("first",b).replace("last",b));hndl.current_page=a;hndl.update();hndl.set_visibility();hndl.update_class();$.isFunction(options.callback)&&options.callback(hndl.start_index,hndl.end_index);return c})}};a.update=function(){hndl.start=eval((hndl.current_page-1)*options.items_on_page)+1;hndl.end=hndl.current_page*options.items_on_page-(options.items_on_page-options.all_items_num%options.items_on_page);if(hndl.current_page-options.pages_step<=0){hndl.prev_pages_num=hndl.current_page-1;hndl.prev_start_page=1}else{hndl.prev_pages_num=options.pages_step;hndl.prev_start_page=hndl.current_page-options.pages_step}if(eval(hndl.current_page)+options.pages_step>=hndl.pages_num){hndl.next_pages_num=hndl.pages_num-hndl.current_page;hndl.next_last_page=hndl.pages_num}else{hndl.next_pages_num=options.pages_step;hndl.next_last_page=eval(hndl.current_page)+options.pages_step}if(hndl.current_page==1){hndl.first_arrow_visible=false;hndl.prev_arrow_visible=false}else{hndl.first_arrow_visible=true;hndl.prev_arrow_visible=true}if(hndl.current_page==hndl.pages_num){hndl.last_arrow_visible=false;hndl.next_arrow_visible=false}else{hndl.last_arrow_visible=true;hndl.next_arrow_visible=true}hndl.start_index=(hndl.current_page-1)*options.items_on_page+1;if(hndl.current_page*options.items_on_page<=options.all_items_num)hndl.end_index=hndl.current_page*options.items_on_page;else hndl.end_index=options.all_items_num;hndl.description=hndl.start_index+" - "+hndl.end_index+" of "+options.all_items_num;hndl.info.html(hndl.description)};a.update();a.draw_paging();a.set_visibility()})}})(jQuery);
