﻿if (!window.UntitledProject5)
	UntitledProject5 = {};
var END =0;
var REACHED_END=0;

UntitledProject5.Page = function() 
{
}

UntitledProject5.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		// Sample event hookup:	
		rootElement.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter));
	    rootElement.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave));
	  	//this.control.content.findName("MyCanvas").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter));
	   	//this.control.content.findName("MyCanvas").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave));
	  
		this.control.content.findName("Pause").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleClickPause));
	    this.control.content.findName("Play").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleClickPlay));
	    this.control.content.findName("Stop").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleClickStop));
		
		this.control.content.findName("PaCentre").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handlePauseChangeColor));
	    this.control.content.findName("PaCentre").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handlePauseChangeBack));
	   	this.control.content.findName("PCentre").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handlePlayChangeColor));
	    this.control.content.findName("PCentre").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handlePlayChangeBack));
	 	this.control.content.findName("SCentre").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handleStopChangeColor));
	    this.control.content.findName("SCentre").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleStopChangeBack));
	 
	   
	   
	    this.control.content.findName("PaCentre").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleSound));
	    this.control.content.findName("PCentre").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleSound));
	    this.control.content.findName("SCentre").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleSound));
	
	   
	  
	   
	    this.control.content.findName("MyVideo").addEventListener("MarkerReached", Silverlight.createDelegate(this, this.onMarkerReached));
	 
	 
	 
	
	},
	
	handleClickPlay: function(sender, eventArgs) 
{
    
	if (END==1)
	{
		sender.findName("MyVideo").stop();
	}
	sender.findName("MyVideo").play();
	REACHED_END=0;
	
},
	
	handleClickPause: function(sender, eventArgs) 
{
   	sender.findName("MyVideo").pause();
	
	if(REACHED_END==1)
	{
		END=1;
	}
	else
	{
	END=0;
	}
	
},
	
	handleClickStop: function(sender, eventArgs) 
{
    sender.findName("MyVideo").stop();
},

	
	
	handleSound: function(sender, eventArgs) 
{
    sender.findName("MySound").stop();
	sender.findName("MySound").play();
	
},





onMarkerReached: function(sender, markerEventArgs) 
{  
		if (markerEventArgs.Marker.Text=="End")
		{
		  END=1;
		  REACHED_END=1;
	    }
		else 
		{
		  END=0;
		}	
},




	
handlePauseChangeColor: function(sender, eventArgs) 
{
    sender.findName("PaButton").Fill="#FF0000FF";
},
handlePauseChangeBack: function(sender, eventArgs) 
{
    sender.findName("PaButton").Fill="#FF222222";
},	

handlePlayChangeColor: function(sender, eventArgs) 
{
    sender.findName("PButton").Fill="#FF0000FF";
},
handlePlayChangeBack: function(sender, eventArgs) 
{
    sender.findName("PButton").Fill="#FF222222";
},	

handleStopChangeColor: function(sender, eventArgs) 
{
    sender.findName("SButton").Fill="#FF0000FF";
},
handleStopChangeBack: function(sender, eventArgs) 
{
    sender.findName("SButton").Fill="#FF222222";
},	

	// Sample event handler
	handleMouseEnter: 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("Storyboard1").Begin();
		
	},
	

	// Sample event handler
	handleMouseLeave: 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("Storyboard1Reverse").Begin();
		
	}

}