var imgTrans = Class.create();
imgTrans.prototype = {
	initialize : function(imgId, linkId, loadingId, textId, objArr, width, height) {
		this.imgId = imgId;
		this.linkId = linkId;
		this.objArr = objArr;
		this.width = width;
		this.height = height;
		this.loadingId = loadingId;
		this.textId = textId;
		//alert(objArr.length);
	},

	imgId : null,
	linkId : null,
	loadingId : null,
	textId : null,
	objArr : null,
	adNum : 0,
	key : 0,
	timer : 7000,
	loaded : false,
	width : 0,
	height : 0,
	imgEle : null,

	playTran : function() {
		if (document.all)
			$(this.imgId).filters.revealTrans.play();
	},

	preloadImg : function() {
		document.imageArray = new Array();
		for (i = 0; i < this.objArr.length; i++) {
		    document.imageArray[i] = new Image;
			document.imageArray[i].src = this.objArr[i].img;
		} 
		this.loaded = true;
		$(this.loadingId).style.display = 'none';
		this.imgEle = document.createElement("img");
		this.imgEle.id = this.imgId;
		this.imgEle.style.width = this.width;
		this.imgEle.style.height = this.height;
		this.imgEle.style.border = 0;
		$(this.linkId).appendChild(this.imgEle);
		this.imgEle.style.filter = "RevealTrans(duration=2,transition=1)";
		this.adNum = rand(this.objArr.length) - 1;
	},

	nextAd : function() {
		if (!this.loaded) {
		    this.preloadImg();
		}
		//alert(this.adNum);
		if(this.adNum < this.objArr.length-1) 
			this.adNum++ ;
		else 
			this.adNum = 0;
		
		if( this.key == 0 ){
			this.key = 1;
		} else if (document.all) {
			$(this.imgId).filters.revealTrans.Transition=23;
			/*
			transition  : 可选项。整数值(Integer)。设置或检索转换所使用的方式。 
			0  : 矩形收缩转换。 
			1  : 矩形扩张转换。 
			2  : 圆形收缩转换。 
			3  : 圆形扩张转换。 
			4  : 向上擦除。 
			5  : 向下擦除。 
			6  : 向右擦除。 
			7  : 向左擦除。 
			8  : 纵向百叶窗转换。 
			9  : 横向百叶窗转换。 
			10  : 国际象棋棋盘横向转换。 
			11  : 国际象棋棋盘纵向转换。 
			12  : 随机杂点干扰转换。 
			13  : 左右关门效果转换。 
			14  : 左右开门效果转换。 
			15  : 上下关门效果转换。 
			16  : 上下开门效果转换。 
			17  : 从右上角到左下角的锯齿边覆盖效果转换。 
			18  : 从右下角到左上角的锯齿边覆盖效果转换。 
			19  : 从左上角到右下角的锯齿边覆盖效果转换。 
			20  : 从左下角到右上角的锯齿边覆盖效果转换。 
			21  : 随机横线条转换。 
			22  : 随机竖线条转换。 
			23  : 随机使用上面可能的值转换。
			*/
			$(this.imgId).filters.revealTrans.apply();
			this.playTran();

		}
		$(this.imgId).src = this.objArr[this.adNum].img;
		//alert(objArr[1].img);
		$(this.linkId).href = this.objArr[this.adNum].link;
		if (this.textId != null) {
		    $(this.textId).innerHTML = this.objArr[this.adNum].text;
		}
		setTimeout(this.nextAd.bind(this), this.timer);	//转换间隔时间
	}
}


var transObj = function(img, link, text) {
	this.img = img;
	this.link = link;
	this.text = text ? text : "";
}

rnd.today=new Date(); 
rnd.seed=rnd.today.getTime(); 
function rnd() { 
	rnd.seed = (rnd.seed*9301+49297) % 233280; 
	return rnd.seed/(233280.0); 
}; 
function rand(number) { 
	return Math.ceil(rnd()*number); 
}; 
