if (!window.SilverlightQuickstart)
	window.SilverlightQuickstart = {};

SilverlightQuickstart.Scene = function() 
{
}

SilverlightQuickstart.Scene.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		// Sample event hookup:	
		rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
	},
	
	// Sample event handler
	handleMouseDown: function(sender, eventArgs) 
	{
	    // The following line of code shows how to find an element by name and call a method on it.
	    // this.control.content.findName("Timeline1").Begin();
	}
}

function ButtonMouseEnter0(sender, eventArgs)
{
    
    if(sender.name == "playButton")
    {
      // Get a reference to the glass rectangle.
      var playBtnGlassRectangle = sender.findName("playBtnGlassRectangle");
      playBtnGlassRectangle.opacity = 1;
    }
    else if(sender.name == "stopButton")
    {
      // Get a reference to the glass rectangle.
      var stopBtnGlassRectangle = sender.findName("stopBtnGlassRectangle");
      stopBtnGlassRectangle.opacity = 1;
    }
    else if(sender.name == "fullScreenButton")
    {
      var fullScreenBtnGlassRectangle= sender.findName("fullScreenBtnGlassRectangle");
      fullScreenBtnGlassRectangle.opacity = 1;
    }
    
}

function ButtonMouseLeave0(sender, eventArgs)
{
    
    if(sender.name == "playButton")
    {
      // Get a reference to the glass rectangle.
      var playBtnGlassRectangle = sender.findName("playBtnGlassRectangle");
      playBtnGlassRectangle.opacity = 0;
    }
    else if(sender.name == "stopButton")
    {
      // Get a reference to the glass rectangle.
      var stopBtnGlassRectangle = sender.findName("stopBtnGlassRectangle");
      stopBtnGlassRectangle.opacity = 0;
    }
    else if(sender.name == "fullScreenButton")
    {
      // Get a reference to the glass rectangle.
      var fullScreenBtnGlassRectangle = sender.findName("fullScreenBtnGlassRectangle");
      fullScreenBtnGlassRectangle.opacity = 0;
    }
}

function ButtonMouseClick0(sender, eventArgs)
{
    
    if(sender.name == "playButton")
    {

      // Run the animation for when the play button is clicked.
      sender.findName("playButtonStoryboard").begin();

      // Swap Pause and Play graphics.
      var playTriangle = sender.findName("playTriangle");
      var leftPauseLine = sender.findName("leftPauseLine");
      var rightPauseLine = sender.findName("rightPauseLine");

      // If the playTriangle is visible then swap the play triangle for
      // the pause lines and start the video.
      if(playTriangle.opacity == 1)
      {
        playTriangle.opacity = 0;
        leftPauseLine.opacity = 1;
        rightPauseLine.opacity = 1;

        // Play the video
        sender.findName("thebutterflyandthebear_wmv").play();
      }
      else
      {
        playTriangle.opacity = 1;
        leftPauseLine.opacity = 0;
        rightPauseLine.opacity = 0;

        // Pause the video
        sender.findName("thebutterflyandthebear_wmv").pause();
      }

    }
    else if(sender.name == "stopButton")
    {
      // Run the animation for when the stop button is clicked.
      sender.findName("stopButtonStoryboard").begin();

      // Stop the video
      sender.findName("thebutterflyandthebear_wmv").stop();

      // If the pause/play button is toggled to the "pause" state,
      // set that button back to the "play" state.
      var playTriangle = sender.findName("playTriangle");
      var leftPauseLine = sender.findName("leftPauseLine");
      var rightPauseLine = sender.findName("rightPauseLine");

      // If the playTriangle is visible then swap the play triangle for
      // the pause lines and start the video.
      if(playTriangle.opacity == 0)
      {
        playTriangle.opacity = 1;
        leftPauseLine.opacity = 0;
        rightPauseLine.opacity = 0;
      }
    }
    else if(sender.name == "fullScreenButton")
    {
      // Run the animation for when the full screen button is clicked.
      sender.findName("fullScreenButtonStoryboard").begin();

      var silverlightControl = sender.getHost();
      silverlightControl.content.fullScreen = !silverlightControl.content.fullScreen;
    }
}

// emphasize function canvas_loaded(sender, args)
function canvas_loaded0(sender, args)
{
  
    var control = sender.getHost();
    control.content.onFullScreenChange = onFullScreenChanged0;
    
}

// emphasize function onFullScreenChanged(sender, args)
function onFullScreenChanged0(sender, args)
{

  
    var silverlightControl = sender.getHost();
    var buttonPanel = sender.findName("buttonContainer");
    var buttonPanelHeight = 0;
    
    if (silverlightControl.content.fullScreen == true)
    {
      buttonPanel.opacity = 0;
    }
    else 
    {
      buttonPanel.opacity = 1;
      buttonPanelHeight = 120;
    } 
    
    var mediaPlayer = sender.findName("thebutterflyandthebear_wmv");
    mediaPlayer.width = silverlightControl.content.actualWidth;
    mediaPlayer.height = silverlightControl.content.actualHeight - buttonPanelHeight;
     

}
