VideoWindow.prototype.RootName = "VideoWindow";
VideoWindow.prototype.s = null;

function VideoWindow(s)
{
    this.s = s;
    this.plugin = plugin;//s.getHost();
	this.MainCanvas = this.s.findname("MainCanvas");
    this.DebugBox =this.s.findname("DebugBox");
    this.xamlObject = this.s.findname(this.RootName);
    this.imageObject = this.s.findname("IntroMovie");
    
    this.CompletedToken = MainCanvas.findname("IntroMovie").addEventListener("CurrentStateChanged", this.OnCurrentStateChanged);
}

VideoWindow.prototype.CompletedToken = null;
VideoWindow.prototype.stopCount = 0;
VideoWindow.prototype.pauseCount = 0;
VideoWindow.prototype.hasPlayed = false;

VideoWindow.prototype.OnCurrentStateChanged = function(sender, e)
{
    //dd("state changed  - " + MainCanvas.findname("IntroMovie")["CurrentState"]);
    var state = MainCanvas.findname("IntroMovie")["CurrentState"];
	
	if (state == "Playing")
		videoWindow.hasPlayed = true;

    if (state == "Stopped")
        videoWindow.stopCount++;
        
    if (state == "Paused")
        videoWindow.pauseCount++;
        
    if (state == "Paused" && videoWindow.hasPlayed)// && videoWindow.stopCount > 0 || state == "Stopped" && videoWindow.pauseCount > 0)
    {
        //dd("stopCount = " + videoWindow.stopCount + "      pauseCount = " + videoWindow.pauseCount);
        videoWindow.OnPaused();
        //videoWindow.Fade(true, 0.5);
        //videoWindow.Show(null, false);
    }
    else
    {
    //    alert("state = " + state);
    }
}

VideoWindow.prototype.videoComplete = false;

VideoWindow.prototype.OnPaused = function()
{
	
    this.videoComplete = true;
    
    if (showVideo)
    {
        mainWindow.OnBeginMain();
	}
}

VideoWindow.prototype.Play = function()
{
    //dd("videoWindow.play");
    this.xamlObject.findname("IntroMovie").play();
}

VideoWindow.prototype.OnSize = function()
{
    // Snap to the bottom of the frame.
    var windowHeight = 294;//this.plugin.content.actualHeight;
    var windowWidth = this.plugin.content.actualWidth;

    this.xamlObject["Canvas.Top"] = 0;
    this.xamlObject["Width"] = windowWidth;
    this.xamlObject["Height"] = windowHeight;
}

VideoWindow.prototype.Show = function(anObj, val)
{
    var obj = anObj;
    if (obj == null) obj = this.s.findname(this.RootName);
    
    if (val == true)
    {
        obj["Visibility"] = "Visible";
    }
    else
    {
        obj["Visibility"] = "Collapsed";
    }
}
