var Jack;
if(!Jack) Jack={};	
Jack.SwapContent=function(FrameBox,SwapTime,WaitTime){
	var SELF=this;
	var alphaValue = 100;
	var keyFrame= new Array();
	var S=false;
	var Reverse=false; //是否倒序显示
	var preloadedimages=new Array()
	var timer=null;
    SELF.frameIndex=0;
	
	function start(){
	   var i;
	   if(FrameBox){
	      preloaded(FrameBox.innerHTML);
	      for(i=0;i<FrameBox.childNodes.length;i++){
	           if(FrameBox.childNodes[i].nodeType==1){
			       keyFrame[keyFrame.length]=FrameBox.childNodes[i].innerHTML;
		       }
	      }
	   }
	   if(keyFrame.length>0){
		  FrameBox.innerHTML=keyFrame[0];
		  FrameBox.style.visibility="visible";
          reStart();
	   }
	}
	function reStart(){
	   clearTimeout(timer);
       timer=setTimeout(filter_1,WaitTime);
	}
    function filter_1(){
        if(S){
            alphaValue++;
        }
		else{
		    alphaValue--;
		}
        if(alphaValue>=100) {
		   alphaValue=100;
           S=false;
        }
		else if(alphaValue<=1){
		   alphaValue=1;
		   S=true;
		}
        if(alphaValue==1) {
           if(!Reverse && SELF.frameIndex>=keyFrame.length-1){
			  SELF.frameIndex=0;
		   }
		   else if(Reverse && SELF.frameIndex<=0){
		      SELF.frameIndex=keyFrame.length-1
		   }
		   else if(Reverse){
		      --SELF.frameIndex;
		   }
           else{
			  ++SELF.frameIndex;
		   }
           FrameBox.innerHTML=keyFrame[SELF.frameIndex];
        }            
        if (isIE()){
             FrameBox.filters.alpha.opacity=alphaValue;
        }
        else{
             FrameBox.style.opacity = alphaValue/100;
        }
		if(alphaValue<100){
		   clearTimeout(timer);
           timer=setTimeout(filter_1,SwapTime);
		}
		else{
		   reStart()
		}
    }
	function isIE(){
        var ret = false
        if (navigator.userAgent.indexOf("MSIE")>0){
            ret =true;    
        }
        return ret;
    }
	SELF.Forward=function(){
	    clearTimeout(timer);
	    alphaValue=0;
	    Reverse=true
		filter_1();
	}
	SELF.Back=function(){
	    clearTimeout(timer);
	    alphaValue=0;
	    Reverse=false
		filter_1();
	}
	function preloaded(s){
	    var reg=/<img[^>]*>/gi
		var reg1=/src=(['"]*)([^'"\s]*)['"\s]/gi
		var i,temp
		var temparray=new Array()
		var imgurl=new Array()
		imgarray=s.match(reg)
		if(imgarray){
			for(i=0;i<imgarray.length;i++){
				temparray=imgarray[i].match(reg1)
				if(temparray.length>0){
				   temp=temparray[0]
				   temp=temp.replace(/src=/gi,"")
				   temp=temp.replace(/['"]/gi,"")
				   imgurl[imgurl.length]=temp
				}
			}
		}
		for(i=0;i<imgurl.length;i++){
			preloadedimages[i]=new Image()
	        preloadedimages[i].src=imgurl[i]
		}
	}
    start()
}
