#{param name=totalPage /}
#{param name=currentPage /}
#{param name=hasNext /}

<%		
	currentPage += 1;
	void render(i) {
	  	if( i == currentPage) { %>
		<li class="active"><a href="javascript:void(0);" data-page="<%=i - 1%>"><%=i%></a></li>
		<%	} else { %>
		<li><a href="javascript:void(0);" data-page="<%=i - 1%>"><%=i%></a></li>
		<%	}   
	}
%>

<div class="pagination uiPageIterator clearfix">
<% if(totalPage < 0 || totalPage > 1) {%> 	
	<ul class="pull-right">
	<%if( currentPage > 1 ) {%>				
	<li><a rel="tooltip" data-placement="bottom" href="javascript:void(0);" data-page="${currentPage - 2}" title="&{pageIterator.label.previous}"><i class="uiIconPrevArrow"></i></a></li>
	<% } else {%>
	<li class="disabled"><a rel="tooltip" data-placement="bottom" title="&{pageIterator.label.previous}"><i class="uiIconPrevArrow"></i></a></li>
	<%}%>
		
	<%
	if (totalPage > 1) {
		int min = 1;
		int max = totalPage;
		int dot1 = dot2 = -1;
		if (totalPage > 5) {
			if (currentPage < 4) {
			   max = 3;
			   dot1 = 4;
			} else if (currentPage >= totalPage - 2) {
			   min = totalPage - 2;
			   dot1 = min - 1;
			} else {
			   min = currentPage - 1;
			   max = currentPage + 1;
			   dot1 = 2;
			   dot2 = totalPage - 1;
			}		
		}
		
		for( i = 1 ; i <= totalPage; i++) { 		
		   	if (i == 1 && min > 1) render(1);
		   	else if (i == min) {
		   	   for (j = min; j <= max; j++) {
		   	   	render(j);	   	      
		   	   }
		   	} else if (i == dot1 || i == dot2) {
					print """ <li class="disabled"><a href="#">...</a></li> """;	   
				} else if (i == totalPage && max < totalPage) render(totalPage);
		}
	}
	%>		
				
	<% if((currentPage < totalPage || totalPage == -1) && hasNext) { %>
	<li><a rel="tooltip" data-placement="bottom" href="javascript:void(0);" data-page="${currentPage}" title="&{pageIterator.label.next}"><i class="uiIconNextArrow"></i></a></li>
	<% } else { %>
	<li class="disabled"><a rel="tooltip" data-placement="bottom" title="&{pageIterator.label.next}"><i class="uiIconNextArrow"></i></a></li>
	<%}%>	
	</ul>
	<%if (totalPage > 1) { %>
	<p class="pull-right">
		<span>&{pageIterator.label.totalPage}:</span>
		<span class="pagesTotalNumber"><%=totalPage%></span>
	</p>
	<%} %>
<%}%>		
</div>
