﻿function VGIImgSequenceFrame(Image, Duration)
{
    this.Image = Image;
    this.Duration = Duration;
}
function VGIImgSequencer(SequencerId, Folder, ImgTagId)
{
    this._SequencerId          = SequencerId;
    this._Sequence             = new Array(); // of VGISequenceFrame
    this._CurrentSequenceFrame = 0;
    this._Folder               = Folder;
    this._ImgTagId             = ImgTagId;
    this._Interval             = null;
    
    this.Add = function(SequenceFrame)
    {
        this._Sequence[this._Sequence.length] = SequenceFrame;
    }
    this.Stop = function()
    {
       if(this._Interval != null)
           clearInterval(this._Interval);
       this._Interval = null;
       this._CurrentSequenceFrame = 0;
    }
    this.Play = function()
    {       
        var Frame = this._Sequence[this._CurrentSequenceFrame];
        var Url = this._Folder + "/" + Frame.Image;
        
        // display new image for this frame
        Node = document.getElementById(this._ImgTagId);
        if(Node != null)
            Node.src = Url;        
        
        this._Interval = setTimeout("VGIImgSequencer_OnFrame(\"" + this._SequencerId +"\");", 
                                    Frame.Duration);

        if(this._CurrentSequenceFrame == this._Sequence.length - 1 )
            this._CurrentSequenceFrame = 0;
        else            
            (this._CurrentSequenceFrame)++;                
    }
    // can be called to start the sequence wiht a delay instead of calling Play() directly
    this.PlayLater = function(Delay)
    {
        if(this._Interval != null)
            clearInterval(this._Interval);          
        this._Interval = setTimeout("VGIImgSequencer_OnFrame(\"" + this._SequencerId +"\");", 
                                    Delay);
    }
}
function VGIImgSequencer_OnFrame(SequencerId)
{      
    // schedule next frame        
    eval(SequencerId+".Play();"); 
}
/* Log: N/A (client) */