// JScript source code

function AnimationDownloader(SLPlugin)
{
    
    // Set the Silverlight Plugin Control
    this.control = SLPlugin.getHost();
    // create downloader object    
    this.downloader = this.control.createObject("downloader");
    this.url;
    this.bytesLoaded; // Can this property be accessed in Silverlight?
    this.bytesTotal; // Can this property be accessed in Silverlight?
    this.percentageDownload;

    this.libraryReady = false;
	this.result;
	
	
}
AnimationDownloader.prototype.DownloadAssets = function(url)
{ 
    this.url = url;
    this.downloader.addEventListener("completed", Silverlight.createDelegate(this, this.OnAnimationDownloadComplete));
    this.downloader.addEventListener("DownloadProgressChanged", Silverlight.createDelegate(this, this.OnAnimationDownloadProgressChanged));
    this.downloader.addEventListener("DownloadFailed", Silverlight.createDelegate(this, this.OnAnimationDownloadFailed));
    this.downloader.open("GET", url);
    this.downloader.send();
}
AnimationDownloader.prototype.ReturnAssets = function()
{
    if ( this.libraryReady == true){
        return this.result;
    }else{
        alert("library not ready:"+ this.url);
        return null;
    }
}  
AnimationDownloader.prototype.OnAnimationDownloadComplete = function(sender, args)
{
    // Remove the Progress Changed Listener once the download is complete
    //this.downloader.removeEventListener("DownloadProgressChanged", Silverlight.createDelegate(this, this.OnAnimationDownloadProgressChanged));
    // HOW Do I return the ResponseText to the Class Token Variable?
    this.libraryReady = true;
    this.result = sender; 
      
}

AnimationDownloader.prototype.OnAnimationDownloadProgressChanged = function(sender, args)
{
   
    // Calculate the downloaded percentage.
   
    this.percentageDownload = sender.downloadProgress;
    
    
}

AnimationDownloader.prototype.OnAnimationDownloadFailed = function(sender, args)
{
    alert("download Failed: "+this.url);
}