function MyApplication8() { }

MyApplication8.prototype = {

    Initialize: function(plugIn, userContext, rootElement)
    {
        // Get and store references to UI components
        this.meMainVideo = rootElement.FindName("meMainVideo");
        this.btnPlayPause = rootElement.FindName("btnPlayPause");
        this.lblPlayPause = rootElement.FindName("lblPlayPause");

        // Hook up event handlers
        this.meMainVideo.AddEventListener("CurrentStateChanged", 
                Silverlight.CreateDelegate(this, this.meMainVideo_CurrentStateChanged));

        this.meMainVideo.AddEventListener("MediaEnded", 
                Silverlight.CreateDelegate(this, this.meMainVideo_MediaEnded));

        this.btnPlayPause.AddEventListener("MouseLeftButtonDown", 
                Silverlight.CreateDelegate(this, this.btnPlayPause_MouseLeftButtonUp));

    },
    
    btnPlayPause_MouseLeftButtonUp: function(sender, e)
    {
        if(this.meMainVideo.CurrentState == "Playing")
        {
            this.meMainVideo.Pause();
        }
        else if(this.meMainVideo.CurrentState != "Closed")
        {
            // Attempt to start playing
            this.meMainVideo.Play();
        }        
    },
    
    meMainVideo_CurrentStateChanged: function(sender, e)
    {
        switch(this.meMainVideo.CurrentState)
        {
            case "Playing":
                this.lblPlayPause.Text = "Pause";
                this.lblPlayPause["Canvas.Left"] = 15;
                break;
            default:
                this.lblPlayPause.Text = "Play";
                this.lblPlayPause["Canvas.Left"] = 22;
                break;
        }  // switch
    },

    meMainVideo_MediaEnded: function(sender, e)
    {
        // Seek back to the beginning
        this.meMainVideo.Position = "0";
    }
}