/*
名称：元素轮显组件
功能：按照一定毫秒数轮换显示某界面元素的子元素
参数：父元素ID(必选)，显示间隔毫秒数(可选，默认3000ms)
*/
function ElementCircle(ContextId){
	this.context = document.getElementById(ContextId);if(!this.context)return;
	//this.context.style.position = "relative";
	this.arr = this.context.childNodes;if(this.arr.length<=0)return;
	this.len = this.arr.length;
	this.time = 3000;//停顿毫秒数
	if(arguments.length>1)this.time = arguments[1];		//第二个参数允许传入毫秒数
	this.index = 0;
	this.Timeout = null;
	//是否百叶窗效果
	this.isBaiye = false;
	if(arguments.length>2)this.isBaiye = arguments[2];		//第三个参数允许百叶窗风格
	//是用visibility还是用display
	this.vis = false;
	try{
		var td = this.context;//.parentNode;
		this.vis = (td && td.style && td.style.position && td.style.position=="relative")?true:false;
	}catch(e){this.vis = false;}
	//设置停止标志，绑定停止事件。
	window["ElementCircle_Stop_"+ContextId] = 0;
	this.SetStop1 = function(){window["ElementCircle_Stop_"+ContextId] = 1; };
	this.SetStop0 = function(){window["ElementCircle_Stop_"+ContextId] = 0; };
	this.isStop = function(){ return window["ElementCircle_Stop_"+ContextId] > 0};
	
	if(this.context.attachEvent){
		for(var i=0; i<this.len;i++  ){
			this.arr[i].attachEvent("onmouseover",this.SetStop1);//此处不用function包含的话，会在设置时自动执行一遍，讨厌！
			this.arr[i].attachEvent("onmouseout",this.SetStop0);
		}
	}else if(this.context.addEventListener!=undefined){
		for(var i=0; i<this.len;i++  ){
			this.arr[i].addEventListener("mouseover", this.SetStop1, true);
			this.arr[i].addEventListener("mouseout", this.SetStop0, true);
		}
	}
	
	//执行轮换过程
	this.Execute = function(){
		var ts = this;
		if(this.len==100)return;
		
		window.clearTimeout(this.Timeout);
		this.Timeout = window.setTimeout(function(){ts.Execute();},this.time);
		
		var a1,a2;
		if(this.index>-1)a1 = this.arr[this.index];
		this.index++;
		if(this.index>=this.arr.length)this.index = 0;
		a2 = this.arr[this.index];
		
		if(!this.isStop()){
			if(!this.isBaiye){
				this.bian(a1,0);	//隐藏前面一个
				this.bian(a2,1);	//显示后面一个
			}else{
				this.baiye(a1,0);	//隐藏前面一个
				this.baiye(a2,1);   //显示后面一个
			}
		}
	};
	this.next = function(){
		if(this.index>-1)this.arr[this.index].style.display = "none";
		this.index++;
		if(this.index>=this.arr.length)this.index = 0;
		this.arr[this.index].style.display = "block";
	};
	this.bian = function(a,b){
		if(a==null)return;
		if(b==1) a.style.display='block';
		else a.style.display='none';
	};
	this.baiye = function(a,b){
		if(a==null)return;
		a.style.filter = "revealTrans(duration=1,transition=9)";
		a.filters.revealTrans.apply();
		if(this.vis)
		{
			a.style.position = "absolute";
			a.style.top = 0;
			a.style.left = 0;
			a.style.display = "";
			if(b==1) a.style.visibility='visible';
			else a.style.visibility='hidden';
		}else{
			if(b==1) a.style.display = "block";
			else a.style.display = "none";
		}
		a.filters.revealTrans.play();
	};
}
