if (!window.heroesMainHeader)
	window.heroesMainHeader = {};

heroesMainHeader.Page = function() 
{
}

heroesMainHeader.Page.prototype =
{

	handleLoad: function(control, userContext, rootElement) 
	{
		var that = this;
		this.control = control;
		this.root = rootElement;
		document.getElementById("silverlightHostHome").style.backgroundImage = "none";
		// Sample event hookup:	
		rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
		
		
		// Retrieve a reference to the plugin.var slPlugin = sender.getHost();    // Create a Downloader object.  
        var downloader = this.control.createObject("downloader");  
          
        // Add DownloadProgressChanged and Completed events.
        downloader.addEventListener("downloadProgressChanged", onDownloadProgressChanged);

        downloader.addEventListener("completed", onDownloadCompleted);
          
        // Initialize the Downloader request.
        // NOTE: downloader APIs disallow file: scheme
        // you must run this sample over localhost: or off a server or the following call will fail
        downloader.open("GET", "silverlight.jpg");
          
        // Execute the Downloader request.
        downloader.send();
        
        // Event handler for updating visual progress indicator
        function onDownloadProgressChanged(sender, eventArgs)
        {
            var progressText = sender.findName("progressText");
            var progressRectangle = sender.findName("progressRectangle");
            
            // Calculate the downloaded percentage.
            var percentage = Math.floor(sender.downloadProgress * 100);
            // Update the Rectangle and TextBlock objects of the visual progress indicator.  
            progressText.text = percentage + "%";
            progressRectangle.width = percentage * 2;
        }
        
        function onDownloadCompleted(sender, eventArgs)  
        {
		    // Retrieve a reference to the plugin.var slPlugin = sender.getHost();    // Create a Downloader object.  
            var downloader2 = that.control.createObject("downloader");  
              
            // Add DownloadProgressChanged and Completed events.
            downloader2.addEventListener("downloadProgressChanged", onDownloadProgressChanged);

            downloader2.addEventListener("completed", onDownload2Completed);
              
            // Initialize the Downloader request.
            // NOTE: downloader APIs disallow file: scheme
            // you must run this sample over localhost: or off a server or the following call will fail
            downloader2.open("GET", "content.xaml");
              
            // Execute the Downloader request.
            downloader2.send();
        }
        
        function onDownload2Completed(sender, eventArgs)  
        {  
            //Add content.xaml to tree
            var control = that.root.getHost();
            
            var originalXaml = sender.ResponseText;
            
            var newContent = control.content.createFromXaml(originalXaml);
            
            // Set the Source property of the Image objects to the specific image  
            // within the downloaded Zip package file.  
            newContent.findName("background").setSource(downloader, "back.png");
            newContent.findName("backBuild").setSource(downloader, "backBuild.png");
            newContent.findName("corr").setSource(downloader, "corr.png");
            newContent.findName("frame").setSource(downloader, "frame.png");
            newContent.findName("frontBuild").setSource(downloader, "frontBuild.png");
            newContent.findName("ground").setSource(downloader, "ground.png");
            newContent.findName("rain").setSource(downloader, "rain.png");
            newContent.findName("title").setSource(downloader, "title.png");
            newContent.findName("title1").setSource(downloader, "title1.png");
            newContent.findName("title2").setSource(downloader, "title2.png");
            newContent.findName("tj").setSource(downloader, "tj.png");
            
            // The XML object is added to the element passed in the constructor
            that.root.children.Add(newContent);
            
            //Start the main animation
            sender.findName("mainAnimation").Begin();
            
        }
	},
	
	// Sample event handler
	handleMouseDown: function(sender, eventArgs) 
	{
		// The following line of code shows how to find an element by name and call a method on it.
		document.location.href = "http://www.microsoft.com/virtualevents/australia/";
	}
}