/macros/SearchPagination
Type: /type/macro
macro: value: $def with (q, first_page, last_page, this_page, per_page)
$# for now this is only for fulltext search.  it's pasted from the advanced search template
$# and modified, so advanced_search.tmpl should be refactored to use this.
$ _ = i18n.get_namespace('/search')
$ bracket_radius = 3
$ start_bracket = max(first_page, min(this_page - bracket_radius, last_page - 2*bracket_radius))
$ end_bracket = min(last_page, max(this_page + bracket_radius, first_page + 2*bracket_radius))

<div class="Pages">
    <strong>$_.more_results:</strong>&nbsp;
    $if this_page > first_page: <a href="$changequery(q=q,offset=(this_page-first_page-1)*per_page)" class="ChoosePage">&lt;&nbsp;PREV</a>&nbsp;
    $if start_bracket > first_page: <a href="$changequery(offset=0)" class="ChoosePage">$first_page</a>
    $if start_bracket > first_page+1: ...
    $for i in range(start_bracket, end_bracket+1):
	$if i == this_page: <b class="YouAreHere">$i</b>&nbsp;
	$else: <a href="$changequery(offset=(i-1)*per_page)" class="ChoosePage">$i</a>&nbsp;
    $if end_bracket < last_page - 1: ...
    $if end_bracket < last_page:
       <a href="$changequery(offset=(last_page-1)*per_page)" class="ChoosePage">$last_page</a>
    $if this_page < last_page: <a href="$changequery(offset=(this_page-first_page+1)*per_page)" class="ChoosePage">NEXT&nbsp;&gt;</a>
</div>