if (!window.WorkingWithMedia)
	window.WorkingWithMedia = {};

WorkingWithMedia.Scene = function() 
{
}

WorkingWithMedia.Scene.prototype =
{
	handleLoad: function(plugIn, userContext, rootElement) 
	{
		this.plugIn = plugIn;
		
	  this.theVideo = rootElement.findName("theVideo");
    this.button = rootElement.findName("ButtonLayer");
    this.downloadStatus = rootElement.findName("downloadStatus");
    this.bufferStatus = rootElement.findName("bufferStatus");
    this.playIcon = rootElement.findName("playIcon");
    this.pauseIcon = rootElement.findName("pauseIcon");

    // Wireup Events
		this.theVideo.addEventListener("MediaOpened", Silverlight.createDelegate(this, this.theVideo_MediaOpened));
		this.theVideo.addEventListener("BufferingProgressChanged", Silverlight.createDelegate(this, this.theVideo_BufferProgress));
		this.theVideo.addEventListener("DownloadProgressChanged", Silverlight.createDelegate(this, this.theVideo_DownloadProgress));
		this.button.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.button_Clicked));
		this.button.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.button_Enter));
		this.button.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.button_Leave));

    // Set Initial Properties
    this.theVideo.source = "bear.wmv"; 
    this.playing = true;
    this.totalProgressWidth = 428;
	},

	theVideo_MediaOpened: function(sender, args) {
    this.button.visibility = "Visible";
  },

  theVideo_DownloadProgress: function(sender, args) {
    this.downloadStatus.Width = this.totalProgressWidth * this.theVideo.DownloadProgress;
  },

  theVideo_BufferProgress: function(sender, args) {
    this.bufferStatus.Width = this.totalProgressWidth * this.theVideo.BufferingProgress;
  },

  button_Enter: function(sender, args) {
    
  },

  button_Leave: function(sender, args) {
    
  },

  button_Clicked: function(sender, args) {

    if (this.playing == true) {
      this.theVideo.pause();
      this.playIcon.visibility = "Visible";
      this.pauseIcon.visibility = "Collapsed";
      this.playing = false;
    } else {
      this.playing = true;
      this.playIcon.visibility = "Collapsed";
      this.pauseIcon.visibility = "Visible";
      this.theVideo.play();
    }
  }

}