// JavaScript Document
//zjpicswitch Build20081212

function zjpicswitch(){
	this.id = arguments[0];	  //参数1：控件ID，必须与对象名相同
	this.width = arguments[1];  //参数2：控件宽度
	if(this.width == null) this.width = 240;
	this.height = arguments[2];  //参数3：控件高度
	if(this.height == null) this.height = 180;
	this.page = arguments[3];  //参数4：是否显示页码(0否 1是)
	if(this.page == null) this.page = 1;
	this.delay = arguments[4];  //参数5：间隔时间(ms)
	if(this.delay == null) this.delay = 5000;
	this.style = arguments[5];  //参数6：切换效果(-1~23)
	if(this.style == null) this.style = 23;
	this.border = arguments[6];  //参数7：边框宽度
	if(this.border == null) this.border = 0;
	this.color = arguments[7];  //参数8：边框颜色
	if(this.color == null) this.color = "#000";
	this.ps = new Array();
	this.sid = null;
	this.flag = 0;
}

zjpicswitch.prototype.show = function(){
	if(this.id == null){
		throw Error("PicSwitch Error");
	}else{
		var boxhtml = "<div id=\""+this.id+"\" style=\"width:"+(this.border*2+this.width)+"px;height:"+(this.border*2+this.height)+"px;overflow:hidden;position:relative;\">";
		boxhtml += "<div id=\""+this.id+"_picbox\" style=\"width:"+this.width+"px;height:"+this.height+"px;";
		if(this.border > 0) boxhtml += "border:"+this.border+"px solid "+this.color+";";
		boxhtml += "\"><a href=\"#\" id=\""+this.id+"_link\" target=\"_blank\"><img src=\"images/blank.gif\" id=\""+this.id+"_pic\" alt=\"\" width=\""+this.width+"\" height=\""+this.height+"\" border=\"0\" onmouseover=\""+this.id+".pause()\" onmouseout=\""+this.id+".start()\"";
		if(navigator.appName == "Microsoft Internet Explorer" && this.style >= 0) boxhtml += " style=\"filter:RevealTrans(Duration=1,Transition="+this.style+")\"";
		boxhtml += " /></a></div>";
		boxhtml += "<div id=\""+this.id+"_page\" style=\"padding:0px "+(this.border+5)+"px "+this.border+"px "+(this.border+5)+"px;top:-"+(this.border+19)+"px;\" class=\"psPage\"></div>";
		boxhtml += "</div>";
		document.write(boxhtml);
		if(this.ps.length > 0){
			document.images[this.id+"_pic"].src = this.ps[0][0];
			document.images[this.id+"_pic"].alt = this.ps[0][2];
			document.getElementById(this.id+"_link").href = this.ps[0][1];
			if(this.page == 1){

			var pagehtml = "";
			for(var i=this.ps.length-1; i>=0; i--){
				if(i == 0){
					pagehtml += "<div id=\""+this.id+"_btn_"+i+"\" class=\"psOn\" onmouseover=\""+this.id+".goto("+i+")\" onmouseout=\""+this.id+".start()\">"+(i+1)+"</div>";
				}else{
					pagehtml += "<div id=\""+this.id+"_btn_"+i+"\" class=\"psOff\" onmouseover=\""+this.id+".goto("+i+")\" onmouseout=\""+this.id+".start()\" style=\"margin-left:5px\">"+(i+1)+"</div>";
				}
			}
			document.getElementById(this.id+"_page").innerHTML = pagehtml;

			}
			this.start();
		}
	}
}

zjpicswitch.prototype.start = function(){
	if(this.sid == null) this.sid = setInterval(this.id+".next()", this.delay);
}

zjpicswitch.prototype.next = function(){
	this.flag++;
	if(this.flag > (this.ps.length-1)) this.flag = 0;
	this.turn();
}

zjpicswitch.prototype.pause = function(){
	clearInterval(this.sid);
	this.sid = null;
}

zjpicswitch.prototype.goto = function(){
	this.flag = arguments[0];
	this.turn();
	clearInterval(this.sid);
}

zjpicswitch.prototype.turn = function(){
	if(navigator.appName == "Microsoft Internet Explorer" && this.style >= 0){
		document.images[this.id+"_pic"].filters.revealTrans.Transition = this.style;
		document.images[this.id+"_pic"].filters.revealTrans.Apply();
	}
	document.images[this.id+"_pic"].src = this.ps[this.flag][0];
	document.images[this.id+"_pic"].alt = this.ps[this.flag][2];
	document.getElementById(this.id+"_link").href = this.ps[this.flag][1];
	if(navigator.appName == "Microsoft Internet Explorer" && this.style >= 0) document.images[this.id+"_pic"].filters.revealTrans.Play();
	if(this.page == 1){
		for(var i=0; i<this.ps.length; i++){
			if(this.flag == i){
				document.getElementById(this.id+"_btn_"+i).className = "psOn";
			}else{
				document.getElementById(this.id+"_btn_"+i).className = "psOff";
			}
		}
	}
	clearInterval(this.sid);
	this.sid = setInterval(this.id+".next()", this.delay);
}

