/*
* 游族滚动广告 js
*  Author chengt
* $Id$
*/
var SlideID = 4;
var	TimeOut1 = null;
var	TimeOut2 = null;
var	TimeOut3 = null;
var TimeOut4 = null;
var TimeOut5 = null;
var SImage   = new Array();
var IndexSlide = {
	Delay:3,
	isIcon:false,
	Init:function(w,h) {
		if(typeof(arrSlidePic) == 'undefined' || arrSlidePic == null) return;
		$("advImg").innerHTML = "";
		var len = arrSlidePic.length;
		
		var strImg		= "";
		var strTitle	= "";
		for(var i = 0;i < len;i++){
			 strImg		+= "<img src='http://pic.uuzu.com/vda_images/"+arrSlidePic[i][0]+"' width='"+w+"' height='"+h+"' border='0'/>";
			 strTitle	+= "<p><a href='"+arrSlidePic[i][1]+"' target='_blank'>"+arrSlidePic[i][2].substring(0,18)+"</a></p>";
		}
		$("advImg").innerHTML = strImg;
		var tl = $("Sildetitle");
		if(typeof(tl)!="undefined" && tl !=null){
			tl.innerHTML = strTitle;
		}
		
		SImage = $("advImg").getElementsByTagName("img");
		var length = SImage.length;
		for(var i=0;i<length;i++){
			if(typeof (SImage[i]) !="undefined"){
				SImage[i].opacity = 0;
			}
			//为所有图片设置一个自定义属性opacity
		} 
		IndexSlide.Start();
	},
	Start:function(){
		clearTimeout(TimeOut1);
		clearTimeout(TimeOut2);
		clearTimeout(TimeOut3);
		clearTimeout(TimeOut4);
		clearTimeout(TimeOut5);
		
		var current = 4;
		if(SlideID < 4){
			current = SlideID;
			if(typeof (SImage[current]) !="undefined"){
				SImage[current].opacity = 0.99;
			}
			
		}
		else{
			if(typeof (SImage[4]) !="undefined"){
				SImage[4].opacity = 0.99;
			}
			
		}

		var tl = $("Sildetitle");

		(function(){
		  TimeOut1 = setTimeout(function(){
				var cOpacity = SImage[current].opacity,
					next = SImage[current+1]? current+1:0;//下一张图片的索引，如果没有就回到第一张

				var nOpacity = SImage[next].opacity;
				cOpacity-=0.05;
				nOpacity+=0.05;
				
				SImage[current].opacity = cOpacity;
				SImage[next].opacity = nOpacity;
				SImage[next].style.display = "block";//确保肯定有一张图片是可见的
				setOpacity(SImage[current]);
				setOpacity(SImage[next]);
				
				//add by eden
				SlideID = next;
				IndexSlide.Action(SlideID);
				
			    if(typeof(tl)!="undefined" && tl !=null){
					tl.scrollTop++;
				}
				
				if(cOpacity >0.95){
					IndexSlide.Action(next);
				}
				if(cOpacity<=0) {
				  
				  SImage[current].style.display = "none";
				  current = next;
				  SlideID = current;
				  if(typeof(tl)!="undefined" && tl !=null){
					tl.scrollTop = 19*current;
				  }
				  
				  TimeOut2 = setTimeout(arguments.callee,IndexSlide.Delay*1000);
				}else{
				  TimeOut3 = setTimeout(arguments.callee,50);
				}
			
		  },100)
		})()

	},
	Stop:function (){
		clearTimeout(TimeOut1);
		clearTimeout(TimeOut2);
		clearTimeout(TimeOut3);
		clearTimeout(TimeOut4);
		clearTimeout(TimeOut5);
	},
	Continue:function(){
		clearTimeout(TimeOut1);
		clearTimeout(TimeOut2);
		clearTimeout(TimeOut3);
		clearTimeout(TimeOut4);
		clearTimeout(TimeOut5);
		this.isIcon = false;
		IndexSlide.Start();
		
		//TimeOut4 = setTimeout("IndexSlide.Start()",300);
	},
	ChangeSlid:function(sid){
		this.Stop();
		this.isIcon=true;
		SlideID = sid;
		this.Action(sid);		
	},
	Action:function(sid){
			var sid1 = sid+1;
			$("btn"+sid1).className = "btn"+sid1+"on";
			for(var i = 1;i<6;i++){
				if((sid1) == i) continue;
				$("btn"+i).className = "btn"+i;
			}
			if(this.isIcon){
				
				IndexSlide.ShowCImg(sid);
			}
	},
	ShowCImg:function(sid){
		if(typeof(SImage[sid]) == 'undefined' || SImage[sid] == null || SImage[sid] == ""){
			return;
		}
		for(var i = 0,len = SImage.length;i<len;i++){
			SImage[i].opacity = 0;
			SImage[i].style.display = "none";
		    setOpacity(SImage[i]);
		}

		SImage[sid].opacity = 0.99;
		SImage[sid].style.display = "block";
		setOpacity(SImage[sid]);

		var tl = $("Sildetitle");
		if(typeof(tl)!="undefined" && tl !=null){
			tl.scrollTop = 19*sid;
		}
		

	},
	OpenUrl:function(){
		var url = arrSlidePic[SlideID][1];
		if(url!=""){
			window.open(url);
		}
	}
}

  var setOpacity =function(obj) {
    if(obj.opacity>.99) {
      obj.opacity = .99;
    }
    obj.style.opacity = obj.opacity;
    obj.style.filter = "alpha(opacity=" + (obj.opacity*100) + ")";
  }



