function MyApplication9() { }

MyApplication9.prototype = {

    Initialize: function(plugIn, userContext, rootElement)
    {        
        // Get and store object references
        this.txtAction = rootElement.FindName("txtAction");
        this.txtStatus = rootElement.FindName("txtStatus");
        
        // Create a new Downloader object
        this.downloader1 = plugIn.CreateObject("Downloader");
        
        // Hook up events
        this.downloader1.AddEventListener("Completed",
                Silverlight.CreateDelegate(this, this.downloader1_Completed));
        this.downloader1.AddEventListener("DownloadProgressChanged",
                Silverlight.CreateDelegate(this, this.downloader1_DownloadProgressChanged));

        // Save the current time
        this._startTime = new Date();
        
        // Start downloading
        this.downloader1.Open("GET", "MyApplication9/preview.png?" + Math.random());
        this.downloader1.Send();
    },
    
    downloader1_Completed: function(sender, e)
    {
        var totalTime = new Date() - this._startTime;
        
        this.txtAction.Text = "Completed in " + totalTime + "ms";
        this.txtStatus.Text = "100%";
        
        /* Other things that you could do with downloaded content
        
        // Set a downloaded image as the source for an Image object
        this.imgSample1.SetSource(sender, "");

        // Set image from a downloaded package, with the filename "preview.png", to an Image object
        this.imgSample1.SetSource(sender, "preview.png");
        
        */
    },
    
    downloader1_DownloadProgressChanged: function(sender, e)
    {
        var percent = Math.floor(sender.DownloadProgress * 100);
        this.txtStatus.Text = percent + "%";
    }

}