<% content_for :css do %>
.index-paging {
text-align: center;
padding-left: 1em;
padding-right: 1em;
background-color: whitesmoke;
}
.paging-number {
display: inline-block;
min-width: 1.2em;
}
<% end %>

<% results.fetch_multiple_pages(false) %>

<% if results.respond_to? :result_offset and
       results.respond_to? :result_limit and
       results.respond_to? :items_available and
       results.result_offset != nil and
       results.result_limit != nil and
       results.items_available != nil
%>
<div class="index-paging">
  Displaying <%= results.result_offset+1 %> &ndash;
  <%= if results.result_offset + results.result_limit > results.items_available
        results.items_available
      else
        results.result_offset + results.result_limit
      end %>
 out of <%= results.items_available %>
</div>

<% if not (results.result_offset == 0 and results.items_available <= results.result_limit) %>

<div class="index-paging">

<% if results.result_offset > 0 %>
  <% if results.result_offset > results.result_limit %>
    <% prev_offset = results.result_offset - results.result_limit %>
  <% else %>
    <% prev_offset = 0 %>
  <% end %>
<% else %>
  <% prev_offset = nil %>
<% end %>

<% this_offset = results.result_offset %>

<% if (results.result_offset + results.result_limit) < results.items_available %>
  <% next_offset = results.result_offset + results.result_limit %>
<% else %>
  <% next_offset = nil %>
<% end %>

<span class="pull-left">
<% if results.result_offset > 0 %>
  <%= link_to raw("<span class='glyphicon glyphicon-fast-backward'></span>"), {:id => object, :offset => 0, :limit => results.result_limit}  %>
<% else %>
  <span class='glyphicon glyphicon-fast-backward text-muted'></span>
<% end %>

<% if prev_offset %>
  <%= link_to raw("<span class='glyphicon glyphicon-step-backward'></span>"), {:id => object, :offset => prev_offset, :limit => results.result_limit}  %>
<% else %>
<span class='glyphicon glyphicon-step-backward text-muted'></span>
<% end %>
</span>

<% first = this_offset - (10 * results.result_limit) %>
<% last = this_offset + (11 * results.result_limit) %>

<% lastpage_offset = (results.items_available / results.result_limit) * results.result_limit %>

<% if last > results.items_available %>
  <% first -= (last - lastpage_offset) %>
  <% last -= (last - results.items_available) %>
<% end %>

<% if first < 0 %>
  <% d = -first %>
  <% first += d %>
  <% last += d %>
<% end %>

<% last = results.items_available if last > results.items_available %>

<% i = first %>
<% n = first / results.result_limit %>

<% if first > 0 %>
&hellip;
<% end %>

<% while i < last %>
<% if i != this_offset %>
  <%= link_to "#{n+1}", {:id => @object, :offset => i, :limit => results.result_limit}, class: 'paging-number' %>
<% else %>
  <span class="paging-number" style="font-weight: bold;"><%= n+1 %></span>
<% end %>
<% i += results.result_limit %>
<% n += 1 %>
<% end %>

<% if last < results.items_available %>
&hellip;
<% end %>

<span class="pull-right">
<% if next_offset %>
  <%= link_to raw("<span class='glyphicon glyphicon-step-forward'></span>"), {:id => @object, :offset => next_offset, :limit => results.result_limit}  %>
<% else %>
<span class='glyphicon glyphicon-forward text-muted'></span>
<% end %>

<% if (results.items_available - results.result_offset) >= results.result_limit %>
  <%= link_to raw("<span class='glyphicon glyphicon-fast-forward'></span>"), {:id => @object, :offset => results.items_available - (results.items_available % results.result_limit),
        :limit => results.result_limit}  %>
<% else %>
  <span class='glyphicon glyphicon-fast-forward text-muted'></span>
<% end %>

</span>

</div>

<% end %>

<% end %>