(function(a){a.fn.tablePagination=function(b){var c={firstArrow:(new Image()).src="/p/elementi/first.gif",prevArrow:(new Image()).src="/p/elementi/prev.gif",lastArrow:(new Image()).src="/p/elementi/last.gif",nextArrow:(new Image()).src="/p/elementi/next.gif",rowsPerPage:5,currPage:1,optionsForRows:[5,10,25,50,100],ignoreRows:[]};b=a.extend(c,b);return this.each(function(){var r=a(this)[0];var h,f,l,i,j,t,p;if(r.id){h="#"+r.id+"+#tablePagination #tablePagination_totalPages";f="#"+r.id+"+#tablePagination #tablePagination_currPage";l="#"+r.id+"+#tablePagination #tablePagination_rowsPerPage";i="#"+r.id+"+#tablePagination #tablePagination_firstPage";j="#"+r.id+"+#tablePagination #tablePagination_prevPage";t="#"+r.id+"+#tablePagination #tablePagination_nextPage";p="#"+r.id+"+#tablePagination #tablePagination_lastPage"}else{h="#tablePagination #tablePagination_totalPages";f="#tablePagination #tablePagination_currPage";l="#tablePagination #tablePagination_rowsPerPage";i="#tablePagination #tablePagination_firstPage";j="#tablePagination #tablePagination_prevPage";t="#tablePagination #tablePagination_nextPage";p="#tablePagination #tablePagination_lastPage"}var s=a.makeArray(a("tbody tr",r));var k=a.grep(s,function(w,v){return(a.inArray(w,c.ignoreRows)==-1)},false);var d=k.length;var u=e();var m=(c.currPage>u)?1:c.currPage;if(a.inArray(c.rowsPerPage,c.optionsForRows)==-1){c.optionsForRows.push(c.rowsPerPage)}function o(x){if(x==0||x>u){return}var y=(x-1)*c.rowsPerPage;var w=(y+c.rowsPerPage-1);a(k).show();for(var v=0;v<k.length;v++){if(v<y||v>w){a(k[v]).hide()}}}function e(){var w=Math.round(d/c.rowsPerPage);var v=(w*c.rowsPerPage<d)?w+1:w;if(a(h).length>0){a(h).html(v)}return v}function n(v){if(v<1||v>u){return}m=v;o(m);a(f).val(m)}function q(){var x=false;var y=c.optionsForRows;y.sort(function(A,z){return A-z});var w=a(l)[0];w.length=0;for(var v=0;v<y.length;v++){if(y[v]==c.rowsPerPage){w.options[v]=new Option(y[v],y[v],true,true);x=true}else{w.options[v]=new Option(y[v],y[v])}}if(!x){c.optionsForRows==y[0]}}function g(){var v=[];v.push("<div id='tablePagination'>");v.push("<span id='tablePagination_perPage'>");v.push("<select id='tablePagination_rowsPerPage'><option value='5'>5</option></select>");v.push("per page");v.push("</span>");v.push("<span id='tablePagination_paginater'>");v.push("<img id='tablePagination_firstPage' src='"+c.firstArrow+"'>");v.push("<img id='tablePagination_prevPage' src='"+c.prevArrow+"'>");v.push("Page");v.push("<input id='tablePagination_currPage' type='input' value='"+m+"' size='1'>");v.push("of <span id='tablePagination_totalPages'>"+u+"</span>");v.push("<img id='tablePagination_nextPage' src='"+c.nextArrow+"'>");v.push("<img id='tablePagination_lastPage' src='"+c.lastArrow+"'>");v.push("</span>");v.push("</div>");return v.join("").toString()}if(a(h).length==0){a(this).after(g())}else{a("#tablePagination_currPage").val(m)}q();o(m);a(i).bind("click",function(v){n(1)});a(j).bind("click",function(v){n(m-1)});a(t).bind("click",function(v){n(m+1)});a(p).bind("click",function(v){n(u)});a(f).bind("change",function(v){n(this.value)});a(l).bind("change",function(v){c.rowsPerPage=parseInt(this.value,10);u=e();n(1)})})}})(jQuery);
