<%  
  def totalPage = uicomponent.getMaxPage();
  def currentPage = uicomponent.currentPage;
  String selected = String.valueOf(currentPage);
  
  void render(i) {
      if( i == uicomponent.currentPage) { %>
    <li class="active"><a href="<%=uicomponent.event(uicomponent.GOPAGE,"$i")%>"><%=i%></a></li>
    <%  } else { %>
    <li><a href="<%=uicomponent.event(uicomponent.GOPAGE,"$i")%>"><%=i%></a></li>
    <%  }   
  }
%>

<div class="pagination uiPageIterator clearfix">
<% if(totalPage > 1) {%>  
  <ul class="pull-right">
  <%if( currentPage > 1 ){%>        
  <li><a href="<%=uicomponent.event(uicomponent.GOPAGE,"${currentPage - 1}")%>" rel="tooltip" data-placement="bottom" title="<%=_ctx.appRes("UIPageIterator.label.previous")%>"><i class="uiIconPrevArrow"></i></a></li>
  <% } else {%>
  <li class="disabled"><a rel="tooltip" data-placement="bottom" title="<%=_ctx.appRes("UIPageIterator.label.previous")%>"><i class="uiIconPrevArrow"></i></a></li>
  <%}%>
  
  <%    
  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) { %>
  <li><a href="<%=uicomponent.event(uicomponent.GOPAGE,"${currentPage + 1}")%>" rel="tooltip" data-placement="bottom" title="<%=_ctx.appRes("UIPageIterator.label.next")%>"><i class="uiIconNextArrow"></i></a></li>
  <% } else { %>
  <li class="disabled"><a rel="tooltip" data-placement="bottom" title="<%=_ctx.appRes("UIPageIterator.label.next")%>"><i class="uiIconNextArrow"></i></a></li>
  <%}%> 
  </ul>
  <p class="pull-right">
    <span><%=_ctx.appRes("UIPageIterator.label.totalPage")%>:</span>
    <span class="pagesTotalNumber"><%=totalPage%></span>
  </p>
<%}%>   
</div>