﻿//文档说明:
//功能:切换图片(含切换效果)
//适用:广告系统
//开发:技术部-小宗
//时间:18:44 2009-09-29

function ColorPair (sColor, sBGColor)
{
	this.m_color = sColor;
	this.m_bgColor = sBGColor;
}

//Interval
//当前对象名称，绑定Div的ID名称,启动时的时延，运行中的昌延
function MultiToggle(instance,oDiv)
{
	//版本信息
	this.Author =(function(){return "Wisdom-Star(宗玓)";})();//属性写法
	this.Version ="1.1";
	this.UpdateTime = "2009年9月24日";
	this.Friend = "流星蝴蝶剑";

	//初始变量
	this.NowFrame = 1;//当前帧
	this.MaxFrame = 5;//总帧
	this.bStart = 0;  //开始帧
	this.speed = 6;//切换速度
	
	this.Seconds = 1000;//1秒=1000毫秒
	//关键变量
	this.instance =instance;//实例名称
//	this.DivObj = document.getElementById("oTransContainer");
	this.DivObj = document.getElementById( "" + oDiv || "Div_MultiToggle");//DIV对象
	this.ImgList = null; 
	
	this.ImgList= this.DivObj.getElementsByTagName("img");//getElementsByTagName

	this.StartDelay = 1;//1秒
	this.RunDelay = 6;//6秒

	//滤镜类型
	this.garTransitions = new Array(24); //arrary of filter strings
	this.g_aColors = new Array(24); // array of colorpair objects

	this.iMaxTransition = 23; // maximum number of transitions supported
	this.iTransNumber = this.iMaxTransition; // current transition

	this.next =1;

	//控件时延
	this.IsDelay = false;//是否延迟:即暂停	
	this.d = new Date();
	this.oldDate = this.d.getTime();

	this.Init();
}


MultiToggle.prototype.Init = function()
{
	if(this.DivObj==null)
		return ;
	
	this.ImgList= this.DivObj.getElementsByTagName("img");//getElementsByTagName
	this.MaxFrame = this.ImgList.length;
	this.next = 0;
	this.NowFrame = -1;	

	this.garTransitions[0] = "progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0, wipeStyle=0, motion='forward')";
	this.iMaxTransition = this.garTransitions.length;
	this.iTransNumber = this.iMaxTransition;
}


MultiToggle.prototype.StartDelayValue = function(StartDelay){this.StartDelay = parseInt(StartDelay || 1,10);}
MultiToggle.prototype.RunDelayValue = function(RunDelay){this.RunDelay = parseInt(RunDelay || 6,10);}

MultiToggle.prototype.fnToggle = function () 
{
	if(this.bStart == 0)
	{
		this.bStart = 1;
		setInterval(this.instance+'.fnToggle()',50);
	}
	else
	{
		if(this.IsDelay==true)
		{
			//开始延时:即在延时后将 IsDelay = false;
			this.d = new Date();
			this.CurrentDate= this.d.getTime() ;
			if(this.oldDate + (this.RunDelay * this.Seconds ) <= this.CurrentDate)				
				this.IsDelay = false;
		}
		else // this.IsDelay = false ;
		{
			this.iTransNumber =0;//24;// parseInt(Math.random() *100,10) % (this.iMaxTransition+1);
			this.DivObj.style.filter = this.garTransitions[this.iTransNumber];
			this.DivObj.filters[0].Apply();
			
			//if(this.next>=0 && this.next<this.ImgList.length) 
				this.ImgList[this.next].style.display = "";
				//window.status = this.NowFrame!= this.next ;
			if(this.NowFrame>=0 && this.NowFrame<this.ImgList.length && this.NowFrame!= this.next ) 
				this.ImgList[this.NowFrame].style.display = "none"; 
			this.DivObj.filters[0].Play(this.speed);//duration=2
			//处理索引
			this.NowFrame = this.next ++;
			if(this.next>=this.ImgList.length) this.next = 0;
			this.d = new Date();
			this.oldDate= this.d.getTime();        
			this.IsDelay =  true;//确定何时开始延时
		}	
	}
}

//document.ready=function(objValue){document.load = objValue}; 

