<?php
if (isset($tpl['paginator']) && $tpl['paginator']['pages'] > 1)
{		
    $get = $controller->_get->raw();
	$page = $tpl['paginator']['pages'];
	if(isset($get['page']) && (int) $get['page'] > 0)
	{
		$page = $get['page'];
	} else {
		$page = 1;
	}
	?>
	<ul class="pagination">
		<?php
		$stages = 3;
		$lastpage = $tpl['paginator']['pages'];
							
		if ($page > 1)
		{
			?>
			<li>
				<a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $page - 1; ?>" data-type="<?php echo @$type;?>" aria-label="<?php __('front_prev');?>">&lt;</a>
			</li>
			<?php
		}
		if ($lastpage < 7 + ($stages * 2))
		{
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
				{
					?><li class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
				}else{
					?><li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $counter; ?>" data-type="<?php echo @$type;?>"><?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 class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
					}else{
						?><li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $counter; ?>" data-type="<?php echo @$type;?>"><?php echo $counter; ?></a></li><?php
					}	
				}
				?>
				<li class="visible-xs-inline-block">
					<span>...</span>
				</li>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $lastpage - 1; ?>" data-type="<?php echo @$type;?>"><?php echo $lastpage - 1; ?></a></li>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $lastpage; ?>" data-type="<?php echo @$type;?>"><?php echo $lastpage; ?></a></li>
				<?php
			}else if($lastpage - ($stages * 2) > $page && $page > ($stages * 2)){
				?>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="1" data-type="<?php echo @$type;?>">1</a></li>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="2" data-type="<?php echo @$type;?>">2</a></li>
				<li class="visible-xs-inline-block">
					<span>...</span>
				</li>
				<?php
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++){
					if ($counter == $page)
					{
						?><li class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
					}else{
						?><li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $counter; ?>" data-type="<?php echo @$type;?>"><?php echo $counter; ?></a></li><?php
					}
				}
				?>
				<li class="visible-xs-inline-block">
					<span>...</span>
				</li>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $lastpage - 1; ?>" data-type="<?php echo @$type;?>"><?php echo $lastpage - 1; ?></a></li>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $lastpage; ?>" data-type="<?php echo @$type;?>"><?php echo $lastpage; ?></a></li>
				<?php
			}else{
				?>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="1" data-type="<?php echo @$type;?>">1</a></li>
				<li><a class="pjCrPaging" href="javascript:void(0);" data-page="2" data-type="<?php echo @$type;?>">2</a></li>
				<li class="visible-xs-inline-block">
					<span>...</span>
				</li>
				<?php
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
					{
						?><li class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
					}else{
						?><li><a class="pjCrPaging" href="javascript:void(0);" data-page="<?php echo $counter; ?>" data-type="<?php echo @$type;?>"><?php echo $counter; ?></a></li><?php
					}
				}
			}	
		}
		if ($page < $counter - 1){
			?>
			<li>
				<a href="javascript:void(0);" class="pjCrPaging" data-page="<?php echo $page + 1; ?>" data-type="<?php echo @$type;?>" aria-label="<?php __('front_next');?>">&gt;</a>
			</li>
			<?php
		}
		?>
	</ul>
	<?php
} 
?>