﻿if (!window.DPEPlayer)
	window.DPEPlayer = {};

DPEPlayer.Page = function() 
{
}

DPEPlayer.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		var media = rootElement.findName("media");
		this.media = media;
		
		var btnPlay = rootElement.findName("btnPlay");
		btnPlay.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handlePlay));
		
		var btnPause = rootElement.findName("btnPause");
		btnPause.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handlePause));
		
		var btnFullScreen = rootElement.findName("btnFullScreen");
		btnFullScreen.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleFullScreen));
		
		this.control.content.onfullScreenChange = this.onFullScreenChanged;
	},
		
	handlePlay: function(sender, args)
	{
		this.media.Play();
	},
	
	handlePause: function(sender, args)
	{
		this.media.Pause();
	},
		
	changeSource: function(source)
	{
	    this.media.Source = source;
	},
	
    handleFullScreen: function(sender, args)
    {
        this.control.content.fullScreen = !this.control.content.fullScreen;         
    },
	
    onFullScreenChanged: function(sender, args)
    {              
        DPEPlayer.Page.prototype.updateLayout(sender, args);
    },
    
    updateLayout: function(sender, args)
    {        
        var content = sender.getHost().content;
        if(content.fullScreen == true)
        {
            DPEPlayer.Page.prototype.updateToFullScreen(sender, content);
        }
        else
        {
            DPEPlayer.Page.prototype.updateToDefault(content);
        }
    },
    
    updateToFullScreen: function(host, content)
    {
        host.findName("media").Width = content.actualWidth;
        host.findName("media").Height = content.actualHeight;
        host.findName("btnPlay").Opacity = 0;
        host.findName("btnPause").Opacity = 0;
        host.findName("btnFullScreen").Opacity = 0;            
        host.findName("msdnLogo").Opacity = 0;     
    },
    
    updateToDefault: function(host, content)
    {
        host.findName("media").Width = 300;
        host.findName("media").Height = 180;       
        host.findName("btnPlay").Opacity = 1;
        host.findName("btnPause").Opacity = 1;
        host.findName("btnFullScreen").Opacity = 1;                 
        host.findName("msdnLogo").Opacity = 1;                           
    }
}