﻿
ImageSequence.prototype.width = -1;
ImageSequence.prototype.height = -1;
ImageSequence.prototype.imageObjects = null;
ImageSequence.prototype.nameToObject = new Object();
ImageSequence.prototype.zipContents = null;
ImageSequence.prototype.suffix = ".jpg";

function ImageSequence(width, height, ext)
{
    this.width = width;
    this.height = height;
    this.imageObjects = new Array();
    this.suffix = ext;
}

ImageSequence.prototype.CreateImages = function(zipContents, baseName, fileExtension, sequenceLength)
{
    this.zipContents = zipContents;
    this.suffix = fileExtension;
    
    for (var i = 1; i <= sequenceLength; i++)
    {
        var imageNumber = "" + i;
        if (imageNumber.length < 2)
            imageNumber = "0" + imageNumber;
       
        var filename = baseName + imageNumber + fileExtension;
             
        var t = '';
        t += '<Image Width="' + this.width + '" Height="' + this.height + '" Visibility="Visible">';
         t += '<Image.RenderTransform>';
            t += '<ScaleTransform CenterX="360" CenterY="147"  ScaleX="1.0" ScaleY="1.0" />';
        t += '</Image.RenderTransform>';
       t += '</Image>';
       

       var imageObj = plugin.content.createFromXaml(t);
       //MainCanvas.children.add(imageObj);
       
       //if (i < 3) alert("Going to set source[" + i + "] from zip = " + zipContents + " to "  + imageObj + "  to  " + filename);  
                   
       imageObj.setSource(zipContents, filename);
       
       //if (i < 3) alert("Set it.");
       
       this.imageObjects.push(imageObj);
       //MainCanvas.findname("MainWindowImageContainer").children.add( imageObj );
        
        this.nameToObject[filename] = imageObj;
    }
}

ImageSequence.prototype.GetImage = function(index)
{
    return this.imageObjects[index];
}

ImageSequence.prototype.FindObject = function(path)
{
    return this.nameToObject[path];
}