﻿if (!window.ReproductorVideo)
	ReproductorVideo = {};

ReproductorVideo.Page = function() 
{
}

ReproductorVideo.Page.prototype =
{
    handleLoad: function(control, userContext, rootElement) {
        this.control = control;

        // Enlace de eventos de ejemplo:
        rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));

        // Eventos del botón Prev.
        this.control.content.findName("btnPrev").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.btnPrev_OnMouseEnter));
        this.control.content.findName("btnPrev").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.btnPrev_OnMouseLeave));
        this.control.content.findName("btnPrev").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.btnPrev_OnClick));

        // Eventos del botón Play.
        this.control.content.findName("btnPlay").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.btnPlay_OnMouseEnter));
        this.control.content.findName("btnPlay").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.btnPlay_OnMouseLeave));
        this.control.content.findName("btnPlay").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.btnPlay_OnClick));

        // Eventos del botón Pause.
        this.control.content.findName("btnPause").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.btnPause_OnMouseEnter));
        this.control.content.findName("btnPause").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.btnPause_OnMouseLeave));
        this.control.content.findName("btnPause").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.btnPause_OnClick));

        // Eventos del botón Stop.
        this.control.content.findName("btnStop").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.btnStop_OnMouseEnter));
        this.control.content.findName("btnStop").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.btnStop_OnMouseLeave));
        this.control.content.findName("btnStop").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.btnStop_OnClick));

        // Eventos de la TV.
        this.control.content.findName("tv").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.Tv_OnMouseEnter));
        this.control.content.findName("canPanel").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.CanPanel_OnMouseLeave));

        // Eventos del botón btnMas.
        this.control.content.findName("btnMas").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.btnMas_OnMouseEnter));
        this.control.content.findName("btnMas").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.btnMas_OnMouseLeave));
        this.control.content.findName("btnMas").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.btnMas_OnClick));

        // Eventos del botón btnMenos.
        this.control.content.findName("btnMenos").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.btnMenos_OnMouseEnter));
        this.control.content.findName("btnMenos").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.btnMenos_OnMouseLeave));
        this.control.content.findName("btnMenos").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.btnMenos_OnClick));

        // Eventos de los videos.
        this.control.content.findName("video1").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.Video1_OnClick));
        this.control.content.findName("video2").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.Video2_OnClick));


    },

    // Controlador de eventos de ejemplo
    handleMouseDown: function(sender, eventArgs) {
        // En la siguiente línea de código se muestra cómo buscar un elemento por su nombre y llamar a un método en él.
        // this.control.content.findName("Storyboard1").Begin();
    },
    // Prev
    btnPrev_OnMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("btnPrev_OnMouseEnter").begin();
    },
    btnPrev_OnMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("btnPrev_OnMouseEnter").stop();
    },
    btnPrev_OnClick: function(sender, eventArgs) {
        this.control.content.findName("video").Position = "00:00:01";
    },

    //Play
    btnPlay_OnMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("btnPlay_OnMouseEnter").begin();
    },
    btnPlay_OnMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("btnPlay_OnMouseEnter").stop();
    },
    btnPlay_OnClick: function(sender, eventArgs) {
        this.control.content.findName("video").Play();
    },

    // Pause
    btnPause_OnMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("btnPause_OnMouseEnter").begin();
    },
    btnPause_OnMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("btnPause_OnMouseEnter").stop();
    },
    btnPause_OnClick: function(sender, eventArgs) {
        this.control.content.findName("video").Pause();
    },

    // Stop
    btnStop_OnMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("btnStop_OnMouseEnter").begin();
    },
    btnStop_OnMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("btnStop_OnMouseEnter").stop();
    },
    btnStop_OnClick: function(sender, eventArgs) {
        this.control.content.findName("video").Stop();
        this.control.content.findName("video").Position = "00:00:01";
    },

    // TV
    Tv_OnMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("Video_OnMouseEnter").begin();
    },
    CanPanel_OnMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("Video_OnMouseEnter").stop();
    },

    // Mas
    btnMas_OnMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("btnMas_OnMouseEnter").begin();
    },
    btnMas_OnMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("btnMas_OnMouseEnter").stop();
    },    
    btnMas_OnClick: function(sender, eventArgs) {
        // Recupero el volumen del Video.
        var vol = this.control.content.findName("video").Volume;

        if (vol < 1) {
            this.control.content.findName("video").Volume = vol + 0.1;
        }


        vol = vol + 0.1;
        vol = String(vol).substring(0, 3);

        switch (vol) {
            case 0:
                this.control.content.findName("v1").Opacity = 1;
                this.control.content.findName("v2").Opacity = 1;
                this.control.content.findName("v3").Opacity = 1;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.1":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 1;
                this.control.content.findName("v3").Opacity = 1;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.2":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 1;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.3":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.4":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.5":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.6":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "0.7":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "0.8":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "0.9":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "1.0":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
        }
    },

    // Menos
    btnMenos_OnMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("btnMenos_OnMouseEnter").begin();
    },
    btnMenos_OnMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("btnMenos_OnMouseEnter").stop();
    },    
    btnMenos_OnClick: function(sender, eventArgs) {
        // Recupero el volumen del Video.
        var vol = this.control.content.findName("video").Volume;

        if (vol > 0) {
            this.control.content.findName("video").Volume = vol - 0.1;
            vol = vol - 0.1;
            vol = String(vol).substring(0, 3);
        }
        else {
            vol = 0;
        }

        switch (vol) {
            case 0:
                this.control.content.findName("v1").Opacity = 1;
                this.control.content.findName("v2").Opacity = 1;
                this.control.content.findName("v3").Opacity = 1;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.1":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 1;
                this.control.content.findName("v3").Opacity = 1;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.2":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 1;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.3":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 1;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.4":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 1;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.5":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 1;
                break;
            case "0.6":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "0.7":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "0.8":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "0.9":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
            case "1.0":
                this.control.content.findName("v1").Opacity = 0;
                this.control.content.findName("v2").Opacity = 0;
                this.control.content.findName("v3").Opacity = 0;
                this.control.content.findName("v4").Opacity = 0;
                this.control.content.findName("v5").Opacity = 0;
                this.control.content.findName("v6").Opacity = 0;
                break;
        }
    },

    // Cambiar Videos
    Video1_OnClick: function(sender, eventArgs) {
        var video;
        var video1;
        var video2;
        video = this.control.content.findName("video").source;
        video1 = this.control.content.findName("video1").source;
        video2 = this.control.content.findName("video2").source;

        this.control.content.findName("video").source = video1;
        this.control.content.findName("video1").source = video;
        this.control.content.findName("video2").source = video2;
    },

    Video2_OnClick: function(sender, eventArgs) {
        var video;
        var video1;
        var video2;
        video = this.control.content.findName("video").Source;
        video1 = this.control.content.findName("video1").Source;
        video2 = this.control.content.findName("video2").Source;

        this.control.content.findName("video").Source = video2;
        this.control.content.findName("video1").Source = video1;
        this.control.content.findName("video2").Source = video;
    }
}