var Prototype = {
	Version: '1.6.0',
	
	Browser: {
		IE:     !!(window.attachEvent && !window.opera),
		Opera: !!window.opera,
		WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
		Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
		MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
	},
	
	BrowserFeatures: {
		XPath: !!document.evaluate,
		ElementExtensions: !!window.HTMLElement,
		SpecificElementExtensions:
			document.createElement('div').__proto__ &&
			document.createElement('div').__proto__ !==
			document.createElement('form').__proto__
	},
	
	ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
	JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
	
	emptyFunction: function() { },
	K: function(x) { return x }
};

//透明度渐变
//id:目标引用，step:变化步长可为正或负，currentValue:当前值，targetValue：目标值
function addOpacity(id,step,currentValue,targetValue)
{
	if(step <0 && currentValue<=targetValue || step >0 && currentValue >= targetValue)
		return;
	currentValue = currentValue + step;
	setOpacity(id,currentValue/100);
	setTimeout(function(){addOpacity(id,step,currentValue,targetValue);}, 50);
}

//设置图片透明度
function setOpacity(id,value)
{
	if(Prototype.Browser.IE) {
		id.filters.alpha.opacity = value*100;
	}
	if(Prototype.Browser.Opera) {
		id.filters.alpha.opacity = value*100;
	}
	if(Prototype.Browser.WebKit) {
		id.style.MozOpacity = value;
		id.style.Opacity = value;
	}
	if(Prototype.Browser.Gecko) {
		id.style.MozOpacity = value;
		id.style.Opacity = value;
	}
	if(Prototype.Browser.MobileSafari) {
		id.style.MozOpacity = value;
		id.style.Opacity = value;
	}
}

var timespan = 5000;
var curPos = 0;
//开始轮换图片
function switchImage(newPos)
{
	prevDiv = document.getElementById("adDiv" + curPos);
	document.getElementById("adBtn" + curPos).className = "";

	if (newPos < 0)
	{
		curPos++;
		if (curPos >= adShow.getElementsByTagName("img").length)
		{
			curPos = 0;
		}
	}
	else
	{
		curPos = newPos;
	}
	nextDiv = document.getElementById("adDiv" + curPos);
	document.getElementById("adBtn" + curPos).className = "lh";
	if (nextDiv.style.display == "none")
	{
		nextDiv.style.display = "inline";
	}
	prevDiv.style.zIndex = -1;
	nextDiv.style.zIndex = 0;
	
	addOpacity(prevDiv,-5,100,0);
	addOpacity(nextDiv,5,0,100);
	
	if (newPos >= 0)   
	{
		clearInterval(theTimer);
	}
	theTimer = setTimeout("switchImage(-1)", timespan);
}
