<?php

	$tickle = 0;

	//echo '<p class="pageNav">';
    if ($_GET['sort']) {
        $params['sort'] = $_GET['sort'];
    }
	if( $pageStart > 0 ) {
		$pageStart -= Config::$pageSize;
		if($pageStart<0)$pageStart=0;
		$params['start'] = (($page-1)*Config::$pageSize);
		echo ' <a href="?' . htmlspecialchars(http_build_query($params)).'"><span>&laquo; previous</span></a>';
		$pageStart += Config::$pageSize;
		$tickle = 1;
	}

	$last = ceil($numItems/Config::$pageSize);
	$current = ceil($pageStart/Config::$pageSize);
	$start = $current - 4;
	if($start < 0 ) $start = 0;
	$end = $start + 8;
		echo ' <strong>page:</strong> ';
		
	// bookend?
	if( $start > 0 ) {
		$params['start'] = 0;
		echo ' <a href="?' . htmlspecialchars(http_build_query($params)).'">[1]</a> ... ';
	}

	// region?
	for( $counter = $start; $counter < $end && $counter < $last; $counter++ ) {
		if($counter == $current ) {
			echo '['.($counter+1).'] ';
		} else {
		    $params['start'] = (($counter)*Config::$pageSize);
			echo '<a href="?' . htmlspecialchars(http_build_query($params)).'">['.($counter+1).']</a> ';
		}
	}

	// bookend?
	if($counter < $last ) {
		$params['start'] = (($last)*Config::$pageSize);
		echo '... <a href="?' . htmlspecialchars(http_build_query($params)).'">['.($last+1).']</a> ';
	}

	if( $numItems > $pageEnd ) {
		if($tickle ) echo ' ';
		$pageStart += Config::$pageSize;
		$params['start'] = (Config::$pageSize *($page+1));
		echo ' <a href="?' . htmlspecialchars(http_build_query($params)).'"><span>next &raquo;</span></a>';
		$pageStart -= Config::$pageSize;
	}
	//echo '</p>';

?>
