function class_ad() {
	var $ = function(id) { return document.getElementById(id); };
	//透明度，动画时间间隔，动画速度，自动运行函数的对象，当前动画的索引值，上一个动画的索引值
	var alpha,time = 1, speed=5, loop, thisAd = 0, oldAd, oUl, oLi, oP, _this = this;
	//按钮的动作
	var action = function(i) {
		oP[i].onmouseup = function() {
			oldAd = thisAd;
			thisAd = i;
			changeIndex(i);
			changeButtonStyle(i);
			change();
		}
	}
	//透明度
	function changeOpacity(obj,value) {
		obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + value + ")";
		obj.style.opacity = value / 100;
		obj.style.MozOpacity = value / 100;
	}
	//改变按钮样式
	var changeButtonStyle = function(i) {
		for (var j=0; j<oP.length; j++) oP[j].className = j==i?"active":"";
	}
	var changeIndex = function(i) {
		for (var y=0; y<oUl.length; y++) oUl[y].style.display="block";
		alpha=100;
		for (var x=0; x<oUl.length; x++) changeOpacity(oUl[x], 100);
		oUl[oldAd].style.zIndex = "3";
		oUl[thisAd].style.zIndex = "2";
		for (var x=0; x<oUl.length; x++) if (x!=thisAd && x!=oldAd) oUl[x].style.zIndex = "1";
	}
	//改变广告
	var change = function() {
		alpha -= speed;
		if (alpha>0) {
			changeOpacity(oUl[oldAd], alpha);
			setTimeout(change, time);
		} else {
			changeOpacity(oUl[oldAd], 0);
			oUl[oldAd].style.display="none";
			alpha=0;
		}
	}
	//自动运行
	var autoRun = function() {
		oldAd = thisAd;
		thisAd = thisAd==oP.length-1?0:thisAd+1;
		changeButtonStyle(thisAd);
		changeIndex(thisAd);
		change();
	}
	this.init = function() {
		//初始化动画
		oUl = $(_this.ad).getElementsByTagName('ul');
		$(_this.ad).onmouseover = function() { clearInterval(loop); };
		$(_this.ad).onmouseout = function() { loop = setInterval(autoRun, _this.looptime*1000); };
		$(_this.button).onmouseover = function() { clearInterval(loop); };
		$(_this.button).onmouseout = function() { loop = setInterval(autoRun, _this.looptime*1000); };
		//初始化按钮
		oP = $(_this.button).getElementsByTagName('p');
		for (var i=0; i<oP.length; i++) action(i);
		loop = setInterval(autoRun, _this.looptime*1000);
	}
}
window.onload = function() {
	var ad_1 = new class_ad;
	ad_1.ad = 'ad_728_90';
	ad_1.button = 'ad_728_90_button';
	ad_1.looptime = 10;
	ad_1.init();
	var ad_2 = new class_ad;
	ad_2.ad = 'ad_468_60';
	ad_2.button = 'ad_468_60_button';
	ad_2.looptime = 10;
	ad_2.init();
	var ad_3 = new class_ad;
	ad_3.ad = 'ad_468_60_2';
	ad_3.button = 'ad_468_60_button_2';
	ad_3.looptime = 10;
	ad_3.init();
}