<?php
/*************************************************************\
+-------------------------------------------------------------+
| 通灵佛教网在线烧香程序 System                                 |
| Copyright (c) 2003-2010 Alfred China                        |
| All rights reserved.                                        |
+-------------------------------------------------------------+
\*************************************************************/
if ( !defined('NetGou_START') ) { header("Location: ../"); die("Access denied"); }

if (empty($page)) $page=1;

$first_page = $objects_per_page*($page-1);

if($first_page <0){
	$first_page = 0;
}
#
# $total_super_pages - how much groups of pages exists
#
$total_super_pages = (($total_nav_pages-1) / ($netgou["max_nav_pages"] ? $netgou["max_nav_pages"] : 10));

#
# $current_super_page - current group of pages
#
$current_super_page = ceil($page / $netgou["max_nav_pages"]);

#
# $start_page - start page number in the list of navigation pages
#
$start_page = $netgou["max_nav_pages"] * ($current_super_page - 1);

#
# $total_pages - the maximum number of pages to display in the navigation bar
# plus $start_page
$total_pages = ($total_nav_pages>$netgou["max_nav_pages"] ? $netgou["max_nav_pages"]+1 : $total_nav_pages) + $start_page;
#
# Cut off redundant pages from the tail of navigation bar
#
if ($total_pages > $total_nav_pages)
	$total_pages = $total_nav_pages;
	
if ($page > 1 and $page > $total_pages) {
	$page = $total_pages - 1;
	$first_page = $objects_per_page*($page-1);
}

if($page > $total_pages){
	$page = $total_pages -1;
}

$navigation_page =  $page;
$start_page = $start_page + 1;

$resultpages=resultpage($page,$total_nav_pages,$pageurl);
function resultpage($page,$total_nav_pages,$pageurl){
	global $temp_img, $lng_inc, $pageurl, $page;
	if ($total_nav_pages<=1){
		return ;
	}else{
		$resultpages="<a href=\"$pageurl&page=1\"><IMG src=$temp_img/first.gif border='0'></a>";
		if($page > 1){
			$previouspage = $page-1;
			$resultpages.="&nbsp;<a href=\"$pageurl&page=$previouspage\"><IMG src=$temp_img/previous.gif border='0'></a>";
		}
		$flag=0;
		for($i=$page-4;$i<=$page-1;$i++)
		{
			if($i<1) continue;
			$resultpages.="&nbsp;<a href=\"$pageurl&page=$i\">$i</a>";
		}
		$resultpages.="&nbsp;&nbsp;<b><font color=#FF0000>$page</font></b>&nbsp;";
		if($page<$total_nav_pages)
		{
			for($i=$page+1;$i<=$total_nav_pages;$i++)
			{
				$resultpages.="&nbsp;<a href=\"$pageurl&page=$i\">$i</a>";
				$flag++;
				if($flag==5) break;
			}
		}
		if($page < $total_nav_pages){
			$nextpage = $page + 1;
			$resultpages.="&nbsp;<a href=\"$pageurl&page=$nextpage\"><IMG src=$temp_img/next.gif border='0'></a>";
		}
		$resultpages.="&nbsp;<a href=\"$pageurl&page=$total_nav_pages\"><IMG src=$temp_img/last.gif border='0'></a>&nbsp;<input type='text' size='2' style='height: 16px; border:1px solid' onkeydown=\"javascript: if(event.keyCode==13) location='$pageurl&page='+this.value;\" value=$nextpage>&nbsp;共<B>$total_nav_pages</B>页,";
		return $resultpages;
	}
}
?>