var uri=location.href.split("/");
var page ;
var uri_last = uri[uri.length-1];
var linkName = uri_last.substring(uri_last.indexOf(theLink)+theLink.length);
var _underline ;
_underline = linkName.indexOf('_') > -1 ;

if( _underline ){
	page = linkName.replace("_","");
}
else{
	page = uri_last.split(",")[1];
}
page	=parseInt(page.split(".")[0]);
var page_offset	=(page==1)?0:(page-1)*page_count;
var prvPage		=(page_offset==0)?1:page-1;
var nxtPage		=(page_offset + page_count >= totalrecord)?page:page+1;
var TotalPage	=Math.ceil(totalrecord/page_count);
TotalPage	=(TotalPage==0)?1:TotalPage;
var pageHTML="";
pageBase="<ul>\r\n";
if(TotalPage==1 || page==1){
	pageHTML+="<li class=\"nextpage\">第一页</li>\r\n";
}	
else if ( _underline )
{
	pageHTML+="<li class=\"nextpage\"><a href='"+theLink+"_1.shtml'>第一页</a></li>\r\n";
}
else{
	pageHTML+="<li class=\"nextpage\"><a href='"+theLink+",1.shtml'>第一页</a></li>\r\n";
}	
if(prvPage==page)
{
	pageHTML+="<li class=\"nextpage\">上一页</li>\r\n";
}	
else if ( _underline )
{
	pageHTML+="<li class=\"nextpage\"><a title='上一页' href='"+theLink+"_"+prvPage+".shtml'>上一页</a></li>\r\n";
}
else{
	pageHTML+="<li class=\"nextpage\"><a title='上一页' href='"+theLink+","+prvPage+".shtml'>上一页</a></li>\r\n";
}
if(TotalPage<=10)
{
	var offset_left=1;
	var offset_right=TotalPage; 
}
else 
{
	if(page-5<1)
	{
		var offset_left=1;
		var offset_right=10; 
	}
	else
	{ 
		if(page+4>TotalPage)
		{
			var offset_left=TotalPage-9;
			var offset_right=TotalPage; 	
		}
		else
		{
			var offset_left=page-5;
			var offset_right=page+4; 	
		}
	}
}
for(var i=offset_left;i<=offset_right;i++)
{
	if(page==i)
	{
		pageHTML+="<li class=\"currentpage\">"+i+"</li>\r\n";
	}		
	else if ( _underline )
	{
		pageHTML+="<li><a href='"+theLink+"_"+i+".shtml'>"+i+"</a></li>\r\n";
	}
	else{
		pageHTML+="<li><a href='"+theLink+","+i+".shtml'>"+i+"</a></li>\r\n";
	}
		
}

if(nxtPage==page)
{
	pageHTML+="<li class=\"nextpage\">下一页</li>\r\n";
}	
else if ( _underline )
{
	pageHTML+="<li class=\"nextpage\"><a title='下一页' href='"+theLink+"_"+nxtPage+".shtml'>下一页</a></li>\r\n";
}
else{
	pageHTML+="<li class=\"nextpage\"><a title='下一页' href='"+theLink+","+nxtPage+".shtml'>下一页</a></li>\r\n";
}
	
if(TotalPage==page || TotalPage==1)
{
	pageHTML+="<li class=\"nextpage\">最后一页</li>\r\n";
}	
else if ( _underline )
{
	pageHTML+="<li class=\"nextpage\"><a href='"+theLink+"_"+TotalPage+".shtml'>最后一页</a></li>\r\n";
}
else{
	pageHTML+="<li class=\"nextpage\"><a href='"+theLink+","+TotalPage+".shtml'>最后一页</a></li>\r\n";
}

pageHTML = pageBase+pageHTML + "</ul>\r\n";
if(document.getElementById("topPage"))
{
	document.getElementById("topPage").innerHTML=TotalPage+"";
}
document.write(pageHTML);