﻿// Use a variable to reference the embedded SWF file.
var flashVideoPlayer;
var isIE;

// When the HTML page loads (through the onLoad event of the <body> tag), it calls the initialize() function.
function initializeVideo() {
    /* Check whether the browser is IE. If so, flashVideoPlayer is
       window.videoPlayer. Otherwise, it's document.videoPlayer. The
       videoPlayer is the ID assigned to the <object> and <embed> tags. */
    isIE = navigator.appName.indexOf("Microsoft") != -1;
    flashVideoPlayer = (isIE) ? window['demoVideo'] : document['demoVideo'];
    if (flashVideoPlayer == null) flashVideoPlayer = document['demoVideo'];
    if (flashVideoPlayer == null) alert('Interactive Video will not work,\r\nthe flashVideoPlayer could not be defined by the browser');
}

/* When the user clicks the play button in the form, update the videoStatus text area, and call the playVideo() function within the SWF file, passing it the URL of the FLV file. */
function callFlashPlayVideo() {
    var comboBox = document.forms['videoForm'].videos;
    var video = comboBox.options[comboBox.selectedIndex].value;
    updateStatus("____" + video + "____");
    flashVideoPlayer.playVideo("http://www.helpexamples.com/flash/video/" + video);
}

// Call the pauseResume() function within the SWF file.
function callFlashPlayPauseVideo() {
    flashVideoPlayer.pauseResume();
}

// The updateStatus() function is called from the SWF file from the onStatus() method of the NetStream object.
function updateStatus(message) {
    if (message == "finished") {
        minimizeVideo();
        //alert('done');
    }
    else if (message == "stopMessage") {
        showStopMessage();
    }
    //document.forms['videoForm'].videoStatus.value += message + "\n";
}
    
function minimizeVideo()
{
    CallFlash('stop');

    hidePlayer();
}

function hidePlayer()
{
    hideVideoControls();
    isHidden = true;
    
	// Set the video player and its container to not visible;
	if (isIE)
	{
        flashVideoPlayer.height = 5;
        flashVideoPlayer.width = 5;
	    document.getElementById("movieObject").height = 5;
	    document.getElementById("movieObject").width = 5;
	}
    else
    {
        flashVideoPlayer.style.display = 'none';
        document.getElementById("movieObject").style.display = 'none';
    }
    // Set the resume button to visible
    document.getElementById("btnResumeVideo").style.display = 'block';
}

function resumeVideo()
{
    isHidden = false;

	document.getElementById("moviePanel").style.left=25;
    document.getElementById("moviePanel").style.width=315;

	// Set the video player and its container to visible;
	if (isIE)
	{
		flashVideoPlayer.height = 560;
	    flashVideoPlayer.width = 300;
    }
    else
    {
    	flashVideoPlayer.style.display = 'block';
        document.getElementById("movieObject").style.display = 'block';
    }    
    // Set the resume button to not visible
    document.getElementById("btnResumeVideo").style.display = 'none';

    // Start the video playing
	CallFlash('play');
}

var isPlaying = true;
var isHidden = false;

function CallFlash(flashParameter)
{
    if (flashParameter == "play")
    {
        if (isPlaying)
        {
            flashParameter = "stop";
            isPlaying = false;
        }
        else
        {
            isPlaying = true;
        }
    }
    else
    {
        isPlaying = false;
    } 

    // Set the property on the flash control
    flashVideoPlayer.pmovie(flashParameter);
}

function setPlayButtonOver()
{
    if (isPlaying)
    {
        document.getElementById("videoPlayButton").src = "images/PauseOver.gif";
        document.getElementById("videoPlayButton").alt = "Pause the Video";
    }
    else
    {
        document.getElementById("videoPlayButton").src = "images/PlayOver.gif";
        document.getElementById("videoPlayButton").alt = "Play the Video";
    }
}
function setPlayButtonOut()
{
    if (isPlaying)
        document.getElementById("videoPlayButton").src = "images/Pause.gif";
    else
        document.getElementById("videoPlayButton").src = "images/PlayClear.gif";
}
function showStopMessage()
{
    if (!confirm('To close this video click the Stop button at the left of the video controls below.' +
    '\r\nOr...\r\n\r\nClick OK to to continue to play the video    or    click Cancel to close it'))
    {
        minimizeVideo();
    }
}
function showVideoControls()
{
    if (! isHidden) document.getElementById("videoControls").style.display='block';
}
function hideVideoControls()
{
    document.getElementById("videoControls").style.display='none';
}
function changeImage(img, newImage)
{
    img.src=newImage;
}

function renderMoviePanel()
{
  var moviePanel = document.getElementById("moviePanel");
  if (moviePanel != null)
  {
    if (moviePanel.style.display !== "none")
    {
        alert('Please use the play button to the left to see the demo or click ' +
        'the Question mark to read more about this video.');
    }
    else
    {
        moviePanel.style.position = "absolute";
        moviePanel.style.display = "block";
        moviePanel.style.left = "25px";
        moviePanel.style.top = "116px";
        moviePanel.style.width = "315px";
        
        moviePanel.innerHTML = getMovieMarkup();
        
        initializeVideo();
    }
  }
}

function getMovieMarkup()
{
    //<div id="moviePanel" style="position: absolute; top: 116px; left: 25px; width: 315px;"
    //    onmouseover="showVideoControls();" onmouseout="hideVideoControls();">
  var markup =  "<div id=\"movieObject\" style=\"position: absolute; top: 0; left: 0; z-index: 80;\">";
  markup += "<object id=\"demoVideo\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ";
  markup += "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" ";
  markup += "width=\"300\" height=\"560\" align=\"left\">";
  markup += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
  markup += "<param name=\"movie\" value=\"demoVideo.swf\" />";
  markup += "<param name=\"quality\" value=\"high\" />";
  markup += "<param name=\"bgcolor\" value=\"#ffffff\" />";
  markup += "<param name=\"wmode\" value=\"transparent\" />";
  markup += "<embed id=\"demoVideo\" src=\"demoVideo.swf\" quality=\"high\" bgcolor=\"#ffffff\" width=\"100%\" ";
  markup += "wmode=\"transparent\" height=\"100%\" swliveconnect=\"true\" name=\"demoVideo\" align=\"middle\"";
  markup += "allowscriptaccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
  markup += "</object>";
  markup += "<div id=\"videoControls\" style=\"width: 128px; height: 64px; z-index: 100; position: absolute;";
  markup += " top: 0px; left: 0px; display: none;\">";
  markup += "<img id=\"videoStopButton\" src=\"images/Minimize.gif\" title=\"Pause and Hide this video\"";
  markup += " alt=\"Pause and Hide this video\" style=\"position: relative; left: 0px;\" onclick=\"minimizeVideo();\" />";
  markup += "<img id=\"videoPlayButton\" src=\"images/About.gif\" title=\"About this video\" alt=\"About this video\"";
  markup += " style=\"position: absolute; left: 64px;\" onclick=\"window.open('InteractiveVideo.aspx','_blank');\" />";
  markup += "</div>";
  markup += "</div>";
  markup += "<img id=\"btnResumeVideo\" style=\"display: none;\" title=\"Resume Video\" alt=\"Resume Video\"";
  markup += " onclick=\"resumeVideo();\" src=\"images/Maximize.gif\" />";
  markup += "</div>";
  
  return markup;
}