var PS_waitTime = 5000; // 切换图片等待时间

var PS_currPic = 1; // 当前图片
var PS_picNo = 0; // 图片总数
var PS_nextPic = 2; // 下一张图片
var PS_waitSwitch = 0; // 等待切换定时函数
/**
 * 生成并开始一个图片切换区域(注：一个页面只能有一个)
 * width: 宽; height:高
 * pics: 图片路径数组; texts: 显示文字数组; linkes: 点击连接数组
 */
function PS_showPicSwitch(width, height, pics, texts, linkes)
{
	PS_picNo = pics.length;
	var bgColor = "#ffffff"; // 背景颜色
	var bgPic = ""; // 背景图片(为空则无)
	var selCol = "#900000"; // 选择按钮被选中颜色
	var selTxCol = "#ffffff"; // 选择按钮文字被选中颜色
	var unSelCol = "#909090"; // 选择按钮颜色
	var unSelTxCol = "#ffffff"; // 选择按钮文字颜色
	document.write("<table width='" + width + "' height='" + height + "' border='0' cellpadding='0' cellspacing='0' bgcolor='" + bgColor + "'><tr><td>");
	document.write("<div style='position:absolute; z-index:1000';><div style='position:absolute; top:" + (height - 20) + "px; z-index:1; visibility: visible; filter:alpha(opacity=80);0 border: 0px;'>");
	document.write("<style>.PS_cssSelBtnUnSel { background: " + unSelCol + "; color: " + unSelTxCol + "; font-size: 12px; cursor: hand; }\r\n.PS_cssSelBtnSel { background: " + selCol + "; color: " + selTxCol + "; font-size: 12px; cursor: hand; }</style>");
	document.write("<table border='0' cellpadding='0' cellspacing='3'><tr><td width='3' height='12'></td>");
	for (i = 0; i < PS_picNo; i++)
	{
		if (0 == i)
		{
			document.write("<td id='PS_selBtn' width='16' height='12' align='center' class='PS_cssSelBtnSel' onClick='PS_selectPic(" + (i + 1) + ")'>" + (i + 1) + "</td>");
		}
		else
		{
			document.write("<td id='PS_selBtn' width='16' height='12' align='center' class='PS_cssSelBtnUnSel' onClick='PS_selectPic(" + (i + 1) + ")'>" + (i + 1) + "</td>");
		}
	}
	document.write("</tr></table></div></div>");
	document.write("<div id='PS_picDiv' style='FILTER: progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=0, motion=reverse); WIDTH: " + width + "px; HEIGHT: " + height + "px'>");
	document.write("<table border='0' cellpadding='0' cellspacing='0'><tr><td width='" + width + "' height='" + height + "'");
	if ("" != bgPic)
	{
		document.write(" background='" + bgPic + "'");
	}
	document.write(">");
	for (i = 0; i < PS_picNo; i++)
	{
		document.write("<a href='" + linkes[i] + "' title='" + texts[i] + "' target='_blank'><img id='PS_pic" + (i + 1) + "' border='0' src='" + pics[i] + "' width='" + width + "' height='" + height + "'");
		if (0 != i)
		{
			document.write(" style='DISPLAY: none;'");
		}
		document.write("></a>");
	}
	document.write("</td></tr></table></div></td></tr></table>");
	PS_waitSwitch = setTimeout("PS_autoSwitch()", PS_waitTime);
}

/**
 * 用户点击切换到图片
 */
function PS_selectPic(page) {

	if (PS_currPic == page)
	{
		return;
	}
	clearInterval(PS_waitSwitch); // 取消当前正在等待的切换
	var obj = PS_picDiv.filters[0];

	if (page > PS_currPic)
	{
		obj.motion = "reverse";
	}
	else
	{
		obj.motion = "forward";
	}
	
	PS_nextPic = page;
	PS_doSwitch();
	PS_currPic = page;
	
	PS_waitSwitch = setTimeout("PS_autoSwitch()", PS_waitTime);

	for (i = 0; i < PS_selBtn.length; i++)
	{
		PS_selBtn[i].className="PS_cssSelBtnUnSel";
	}
	PS_selBtn[page - 1].className="PS_cssSelBtnSel";
}

function PS_doSwitch() {
	    PS_picDiv.filters[0].Apply();
		document.images['PS_pic' + PS_nextPic].style.display = "";
		document.images['PS_pic' + PS_currPic].style.display = "none"; 
		PS_picDiv.filters[0].Play(duration = 2);
}

function PS_autoSwitch(){
	page = PS_currPic + 1;
	if (page > PS_picNo)
	{
		page = 1;
	}
	PS_selectPic(page);
}
