// JavaScript Document
var PageTurning = Class.create({

	 initialize: function(current,total,filename,ext) {
		this.current 	= 	current;	//当前页
		this.total 		= 	total;		//总页数
		this.filename	=	filename;	//文件名
		if(typeof(ext)!="undefined") {
			this.ext	=	ext;		//扩展名
		}else{
			this.ext	=	".shtml";
		}
	 },
	 speak: function() {
		var prev	="<a href=\"" + this.getHref(this.current-1) + "\"> <  上一页</a>";
		var next	="<a href=\"" + this.getHref(this.current+1) + "\">下一页  > </a>";
		var i		=0;
		if(this.current==1 && this.total>1 ){	//判断上一页是否可用
			document.write("<span class=\"disabled\"> <  上一页</span>");
		}else{
			document.write(prev);
		}
		if(this.total<=9){		//总页数少于等于9的情况
			for(i=1 ; i <= this.total;i++){
				if(i!=this.current){
					var String1 = "<a href=\"" + this.getHref(i) + "\">";
					var String2 = "</a>";
					document.write(String1);
					document.write(i);
					document.write(String2);
				}else{
					document.write("<span class=\"current\">");
					document.write(i);
					document.write("</span>");
				}
			}
		}else{		//总页数大于等9的情况
			switch (true){
				case this.current <= 5	:
					for(i=1 ; i <= 5;i++){
						if(i!=this.current){
							var String1 = "<a href=\"" + this.getHref(i) + "\">";
							var String2 = "</a>";
							document.write(String1);
							document.write(i);
							document.write(String2);
						}else{
							document.write("<span class=\"current\">");
							document.write(i);
							document.write("</span>");
						}
					}
					document.write("...");
					for(i=this.total-3 ; i <= this.total;i++){
							var String1 = "<a href=\"" + this.getHref(i) + "\">";
							var String2 = "</a>";
							document.write(String1);
							document.write(i);
							document.write(String2);
					}
					break;
				case this.current >= this.total-5	:
					for(i=1 ; i <= 4;i++){
							var String1 = "<a href=\"" + this.getHref(i) + "\">";
							var String2 = "</a>";
							document.write(String1);
							document.write(i);
							document.write(String2);
					}
					document.write("...");
					for(i=this.total-4 ; i <= this.total;i++){
						if(i!=this.current){
							var String1 = "<a href=\"" + this.getHref(i) + "\">";
							var String2 = "</a>";
							document.write(String1);
							document.write(i);
							document.write(String2);
						}else{
							document.write("<span class=\"current\">");
							document.write(i);
							document.write("</span>");
						}
					}
					break;
				default :
					for(i=1 ; i <= 2;i++){
							var String1 = "<a href=\"" + this.getHref(i) + "\">";
							var String2 = "</a>";
							document.write(String1);
							document.write(i);
							document.write(String2);
					}
					document.write("...");
					for(i = this.current - 2 ; i <= this.current + 2;i++){
						if(i!=this.current){
							var String1 = "<a href=\"" + this.getHref(i) + "\">";
							var String2 = "</a>";
							document.write(String1);
							document.write(i);
							document.write(String2);
						}else{
							document.write("<span class=\"current\">");
							document.write(i);
							document.write("</span>");
						}
					}					
					document.write("...");
					for(i=this.total-1 ; i <= this.total;i++){
							var String1 = "<a href=\"" + this.getHref(i) + "\">";
							var String2 = "</a>";
							document.write(String1);
							document.write(i);
							document.write(String2);
					}
			}
		}

		if(this.current==this.total){	//判断下一页是否可用
			document.write("<span class=\"disabled\">下一页  > </span>");
		}else{
			document.write(next);
		}
	 },
	getHref:function(num){
		if(num==1){
			return this.filename + this.ext;
		}else{
			return this.filename + "_" + num +  this.ext;
		}
	}

});

