<div class="paginator paginator-outer">
	<?php
	if (isset($tpl['paginator']))
	{
		$query_string = preg_replace('/controller=pjWebPages&action=pjActionSearch&?/', '', $_SERVER['QUERY_STRING']);
		$query_string = preg_replace("/&?page=\d+/", "", $query_string);
		$query_string = preg_replace("/&?language=([a-z]{2})/", "", $query_string);
		$query_string = preg_replace("/&?is_best_deal=1,2/", "", $query_string);
		$query_string = trim($query_string, '&');
		$url = sprintf("%s%s/#!/search/%s", $URL, (!isset($_GET['is_best_deal']) ? 'holiday-packages' : 'best-deals'), $query_string);
		$page = isset($_GET['page']) && (int) $_GET['page'] > 0 && (int) $_GET['page'] <= $tpl['paginator']['pages'] ? (int) $_GET['page'] : 1;
		?>
		<ul class="paging-list">
			<?php
			$stages = 3;
			$lastpage = $tpl['paginator']['pages'];
								
			if ($page > 1)
			{
				?><li><a class="paging-prev" href="<?php echo $url; ?>&amp;page=<?php echo $page - 1; ?>"><?php __('front_paging_previous'); ?></a></li><?php
			}
			if ($lastpage < 7 + ($stages * 2))
			{
				for ($counter = 1; $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
					{
						?><li><span class="paging-current"><?php echo $counter; ?></span></li><?php
					} else {
						?><li><a href="<?php echo $url; ?>&amp;page=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
					}
				}
			} else if ($lastpage > 5 + ($stages * 2)) {
				
				if ($page < 1 + ($stages * 2))
				{
					for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
					{
						if ($counter == $page){
							?><li><span class="paging-current"><?php echo $counter; ?></span></li><?php
						} else {
							?><li><a href="<?php echo $url; ?>&amp;page=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
						}
					}
					?>
					<li><span class="paging-dot">...</span></li>
					<li><a href="<?php echo $url; ?>&amp;page=<?php echo $lastpage - 1; ?>"><?php echo $lastpage - 1; ?></a></li>
					<li><a href="<?php echo $url; ?>&amp;page=<?php echo $lastpage; ?>"><?php echo $lastpage; ?></a></li>
					<?php
				} else if ($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) {
					?>
					<li><a href="<?php echo $url; ?>&amp;page=1">1</a></li>
					<li><a href="<?php echo $url; ?>&amp;page=2">2</a></li>
					<li><span class="paging-dot">...</span></li>
					<?php
					for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
					{
						if ($counter == $page)
						{
							?><li><span class="paging-current"><?php echo $counter; ?></span></li><?php
						} else {
							?><li><a href="<?php echo $url; ?>&amp;page=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
						}
					}
					?>
					<li><span class="paging-dot">...</span></li>
					<li><a href="<?php echo $url; ?>&amp;page=<?php echo $lastpage - 1; ?>"><?php echo $lastpage - 1; ?></a></li>
					<li><a href="<?php echo $url; ?>&amp;page=<?php echo $lastpage; ?>"><?php echo $lastpage; ?></a></li>
					<?php
				} else {
					?>
					<li><a href="<?php echo $url; ?>&amp;page=1">1</a></li>
					<li><a href="<?php echo $url; ?>&amp;page=2">2</a></li>
					<li><span class="paging-dot">...</span></li>
					<?php
					for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
					{
						if ($counter == $page)
						{
							?><li><span class="paging-current"><?php echo $counter; ?></span></li><?php
						} else {
							?><li><a href="<?php echo $url; ?>&amp;page=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
						}
					}
				}
			}
			if ($page < $counter - 1)
			{
				 ?><li><a class="paging-next" href="<?php echo $url; ?>&amp;page=<?php echo $page + 1; ?>"><?php __('front_paging_next'); ?></a></li><?php
			}
			?>
		</ul>
		<?php
	}
	$item_per_page = __('item_per_page', true);
	ksort($item_per_page);
	?>
	<div class="paging-options form">
		<label for="per-page"><?php __('front_label_show'); ?></label>
		<span class="paging-options-per-page">
			<select id="per-page" name="per-page" class="form-field">
				<?php
				foreach ($item_per_page as $k => $v)
				{
					?><option value="<?php echo $k; ?>"<?php echo $row_count != $k ? NULL : ' selected="selected"'; ?>><?php echo pjSanitize::html($v); ?></option><?php
				}
				?>
			</select>
		</span>
		<label for="per-page"><?php __('front_label_per_page'); ?></label>
	</div>
</div>