if (!window.WLM_Inicio)
	window.WLM_Inicio = {};

WLM_Inicio.InitJScene = function() 
{
}

WLM_Inicio.InitJScene.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		var downloader = control.createObject("downloader");
		
		downloader.addEventListener("downloadProgressChanged", downloadChanged);
    downloader.addEventListener("completed", downloadCompleted);

	  downloader.open("GET", "silverlightj/index.zip");
	  downloader.send();

	}
}

function downloadChanged(sender, args)
{
    //var done = Math.floor(sender.downloadProgress * 100)/100;
    var done = sender.downloadProgress;
	//var progress = sender.findName("loadingText");
	//progress.text = "Loading... " + (done * 100) + "%";
	var barLength = done * 468.5;
	var progressBar = sender.findName("barLoaded");
	progressBar.width = barLength;
	var txtWLM = sender.findName("WLMTextBlock");
	txtWLM.opacity = (1.000 - done/2);
}

function downloadCompleted(sender, args)
{
    // Make sure the download was ok
    if (sender.status != 200) 
    {
        alert("Init download failed");
        return;
    }

    // Hide the Loading...
    // sender.findName("loadingText").opacity = 0;

    // Build the Banner XAML
    var theXaml = sender.getResponseText("WLMInit.xaml");
    var theContent = sender.getHost().content.createFromXaml(theXaml);

    // Add to the Root
    //var root = sender.findName("root");
    //root.children.clear();
    //root.children.insert(0, theContent);

    var rootCanvas = theContent.findName("WLM_Init");

    setImages(theContent, sender);

    // Add to the Root
    var root = sender.findName("root");
    root.children.clear();
    root.children.insert(0, theContent);

}

function setImages(content, sender)
{
    // Enumerate the children of the Canvas object.
    for (i = 0; i < content.children.count; i++)
    {
        var child = content.children.getItem(i);
        if (child.toString() == "Image")
        {
            //alert(i + ": " + child.toString() + "; name: " + child.name + "; source: " + child.source);
            // Set the Image
            var theImage = content.findName(child.name);
            theImage.setSource(sender, child.source);
        }
    }    
}
function getChildren(parent, index)
{
    // Enumerate the children of the Canvas object.
    for (i = 0; i < parent.children.count; i++)
    {
        var child = parent.children.getItem(i);

        // Display the index and type of the child object.
        alert(i + ": " + child.toString() + "; name: " + child.name + "; source: " + child.source);
    }
}


