﻿
if (!window.VideosTab)
	VideosTab = {};

VideosTab.Page = function() 
{
  this.videoRootUrl = "http://mediadl.microsoft.com/MediaDL/WWW/l/learningspace/";
}

VideosTab.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
	  
	  this.currentVideo = null;
	  this.videoTitleCanvas = this.control.content.findName("VideoTitleCanvas");
	  this.videoTitle = this.control.content.findName("VideoTitle");
	  this.nowPlayingTitle = this.control.content.findName("NowPlayingTitle");
	  
		this.fullScreenButton = this.control.content.findName("FullScreen");
		this.fullScreenButton.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.fullScreenButtonClick));
		
	  this.videoPlayer = new EmbeddedPlayer(this.control, this.control.content.findName("Page"), 0,
	                        640,
	                        480,
	                        this.control.id);
	  
	  this.videos = { NFVHE: "nfvHE.wmv",
	                  NFVK12: "nfvK12.wmv",
	                  Vision: "vision.wmv"
	                };
	                
	  this.videoThumbs = { nfvHE: this.control.content.findName("NFVHE"),
	                       nfvK12: this.control.content.findName("NFVK12"),
	                       vision: this.control.content.findName("Vision")
	                     };

    var videoMouseEnterDelegate = Silverlight.createDelegate(this, this.videoMouseEnter);
    var videoMouseLeaveDelegate = Silverlight.createDelegate(this, this.videoMouseLeave);	                     
    var videoMouseClickDelegate = Silverlight.createDelegate(this, this.videoMouseClick);	                     
	  for(var v in this.videoThumbs)
	  {
	    this.videoThumbs[v].addEventListener("MouseEnter", videoMouseEnterDelegate);
	    this.videoThumbs[v].addEventListener("MouseLeave", videoMouseLeaveDelegate);
	    this.videoThumbs[v].addEventListener("MouseLeftButtonUp", videoMouseClickDelegate);
	  }
	  
	  this.videoMouseEnterAnim = this.control.content.findName("Video_MouseEnter");
	  this.videoMouseLeaveAnim = this.control.content.findName("Video_MouseLeave");
	},	
	
	videoMouseEnter: function(sender, eventArgs)
	{
	  this.videoMouseEnterAnim.Stop();
	  this.videoMouseEnterAnim["Storyboard.TargetName"] = sender.Name;
	  this.videoMouseEnterAnim.Begin();
	  
	  this.videoTitle.Text = sender.Tag;
	  this.videoTitle["Canvas.Left"] = (this.videoTitleCanvas.Width / 2) - (this.videoTitle.ActualWidth / 2);
	},
	
	videoMouseLeave: function(sender, eventArgs)
	{
	  this.videoMouseLeaveAnim.Stop();
	  this.videoMouseLeaveAnim["Storyboard.TargetName"] = sender.Name;
	  this.videoMouseLeaveAnim.Begin();
	  
	  this.videoTitle.Text = "";
	},
	
	videoMouseClick: function(sender, eventArgs)
	{
	  this.nowPlayingTitle.Text = sender.Tag;	  
	  this.currentVideo = sender.Name;
	  this.videoPlayer.ChangeVideo(this.videoRootUrl + this.videos[sender.Name]);
	  
	  var linkName = getPage() + "_" + getSelectedSlider() + "_videos_" + 
	    this.videos[sender.Name].substring(0, this.videos[sender.Name].indexOf('.wmv'));
	    
	  trackLink(true, 'o', linkName);
	},
	
	StopVideo: function(sender, eventArgs)
	{
	  this.videoPlayer.Stop();
	  this.nowPlayingTitle.Text = '';
	},
	
	fullScreenButtonClick: function(sender, eventArgs)
	{
	  if(this.videos[this.currentVideo])
	  {
		  this.videoPlayer.Stop();
		  displayFullScreenPlayer(this.videoRootUrl + this.videos[this.currentVideo]);
		}
	}
}