// 首页轮换广告
var MyRotater = new Object();
MyRotater.rotateTimer = null; // 计数器
MyRotater.myInterval = 3000;  // 间隔时间
MyRotater.curId = 0; // 当前广告
MyRotater.adImgs = new Array(); // 广告图片数组
MyRotater.adTxts = new Array(); // 广告文子数组
MyRotater.adNum = 0; // 广告数量


// 注册事件
MyRotater.regADEvent = function() {
	for (var i = 0; i < this.adNum; i++) {
		this.adTxts[i].onmouseover = function() {
			clearTimeout(MyRotater.rotateTimer);
			MyRotater.changeAD(this.id.split('_')[2]-1);
		}
		this.adTxts[i].onmouseout = function() {
			MyRotater.restartRotate();
		}
	}
}


// 初始化轮换
MyRotater.initRotate = function(nInterval) {
	if(!isNaN(nInterval)) MyRotater.myInterval = nInterval;
	
	this.adImgs = $ID('ad_img').getElementsByTagName('li');
	this.adTxts = $ID('ad_txt').getElementsByTagName('li');
	this.adNum = this.adImgs.length;
	this.regADEvent();
	this.rotateAD();
}


// 当前广告
MyRotater.setRotate = function() {
	for (var i = 0; i < this.adNum; i++) {
		if (i == this.curId) {
			this.adImgs[i].className = '';
			this.adTxts[i].className = 'current';	
		}
		else {
			this.adImgs[i].className = 'none';
			this.adTxts[i].className = '';	
		}
	}
}


// 开始广告轮换
MyRotater.rotateAD = function() {
	this.setRotate();
	(this.curId == (this.adNum - 1)) ? this.curId = 0 : this.curId++;
	this.rotateTimer = setTimeout("MyRotater.rotateAD()", this.myInterval);
}


// 重新开始广告轮换
MyRotater.restartRotate = function() {
	clearTimeout(this.rotateTimer);
	(this.curId == (this.adNum - 1)) ? this.curId = 0 : this.curId++;
	this.rotateTimer = setTimeout("MyRotater.rotateAD()", this.myInterval);
}


// 改变当前广告
MyRotater.changeAD = function(nGotoNo) {
	this.curId = nGotoNo;
	this.setRotate();
}