﻿if (!window.site)
	window.site = {};

site.Page = function() 
{
}

site.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		
		this.files = Array("images/bases.png",
"images/cielo.jpg",
"images/edificio1.png",
"images/edificio2.png",
"images/edificio3.png",
"images/flecha.png",
"images/inter-grande.png",
"images/logotipo.png",
"images/participe.png",
"images/sorteo.png",
"images/texto.png",
"images/titu y linea.png",
"images/xbox360.jpg");

		this.filesCargadas = 0;
		if(!this.downloaded)
		{
            this.downloader = this.control.createObject("downloader");

            // Add DownloadProgressChanged and Completed events.
            //downloader.addEventListener("downloadProgressChanged", Silverlight.createDelegate(this, this.handleProgressChanged));
            this.downloader.addEventListener("completed", Silverlight.createDelegate(this, this.handleCompleted));
            // 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
           
            this.downloader.open("GET", this.files[this.filesCargadas]);

            // Execute the Downloader request.
            this.downloader.send();
		}
		
		this.downloaded = true; 
		// Sample event hookup:	
//		rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
	    this.control.content.findName("boton").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.linkTo));
        this.control.content.findName("bases").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.linkTo));	    
	},
	
	initPeli:function()
	{
	    this.control.content.findName("inicio").Visibility="Visible";
	    this.control.content.findName("final").Visibility="Visible";
	   this.control.content.findName("init").Begin();
	},
    handleCompleted:function(sender, eventArgs){
	     this.filesCargadas++
	     var percent = (this.filesCargadas * 100) / this.files.length
//         this.control.content.findName("cargador").text = "Cargando: "+Math.round(percent)+"%"// ("+this.files[this.filesCargadas]+")";
//	     alert(percent)
	     if(this.filesCargadas<this.files.length){
	        this.downloader.open("GET", this.files[this.filesCargadas]);
            this.downloader.send();
         }else{
            this.initPeli();
         }
	},
	linkTo:function(sender, eventArgs)
	{
        switch(sender.name)
        {
            case "boton":
                window.location="https://profile.microsoft.com/RegSysProfileCenter/wizard.aspx?wizid=226eb9ee-ebfd-4518-9d7b-6fecce3017c3&lcid=1034";
                break;
            case "bases":
                window.open("http://www.microsoft.es/enterprise/bcaptacion.aspx");
                break;
        
        }	    
	}
}