<!-- 

//Copyright C4 2006
//Code to control the Windows Media Player object, and display its progress
//Written by Adam Goodrich

//Set these up based on the size of the progress bar
var numSlicesInProgressBar = 21;// Number of equal sized slices of progress bar
var displayProgressBar = true;	// Determine whether or not to display progress bar
var heightOfProgressBar = 5;	// Height of progress bar (in pixels)
var deltaFFRew  = 20;			// Fast forward & rewind chunk size for pure video

//Some handy images - change them if you need to
var emptyBarImg = new Image();			//the image that signifies an empty bar
var fullBarImg 	= new Image();			//the image that signifies an full bar
var playImg 	= new Image();			//the image to be displayed when we play
var pauseImg 	= new Image();			//the image to be displayed when we pause
var muteOvrImg 	= new Image();			//the image to be displayed when mute is on
var muteImg 	= new Image();			//the image to be displayed when mute is off

//and the corresponding url of the images
emptyBarImg.src = "/images/playerImages/vidProgressOff.gif";	
fullBarImg.src 	= "/images/playerImages/vidProgressOn.gif";
playImg.src 	= "/images/playerImages/buttonPlayVideo.gif";
pauseImg.src 	= "/images/playerImages/buttonPauseVideo.gif";
muteOvrImg.src 	= "/images/playerImages/buttonSoundMuteOvr_lrg.gif";
muteImg.src 	= "/images/playerImages/buttonSoundMute_lrg.gif";

//Determine slice width, and allow for rounding errors - calculate each slice as a percentage
var sliceWidth = 100 / numSlicesInProgressBar;
var leftOverWidth = 100 - (sliceWidth * numSlicesInProgressBar);

//Media player status 
var running	= true;				//are we playing or not - default is yes
var currClipPosition = 0;			//current position within the video (usually seconds)
var clipDuration = 100;				//total duration of the video (usually seconds)
var playedClip = 0;

//Set the progress bar to its empty state
function initializeProgressBar()
{
	var p;

	//check to see if we have a document.img tage
	if (document.getElementById("img0") == null)
	{
		setTimeout("initializeProgressBar()",1000);
		return;
	}

	if (displayProgressBar)
	{	
		for (p=0; p<numSlicesInProgressBar; p++)
		{
			eval("document.img" + p + ".src=emptyBarImg.src");
		}
		updateProgressBar();
	}
	updatePlayButton();
}

//Update the state of the progress bar - this will keep running until video is stopped
function updateProgressBar()
{
	var i, p;
	//only update the clip duration and position if we are playing
	if (running)
	{
		//update the clip status
		oldCurrClipPosition = currClipPosition;
		currClipPosition = Math.floor(MediaPlayer1.CurrentPosition);
		clipDuration = Math.floor(MediaPlayer1.Duration);
		
		//signal that we have reached the end of the clip if necessary
		if (currClipPosition < oldCurrClipPosition)
		{
			CheckPlayMode();
		}
		else if (currClipPosition > 0)
		{
			if (currClipPosition == clipDuration)
			{
				CheckPlayMode();
			}
		}
	}
	
	//draw where we were up to the last time we checked
	if (displayProgressBar)
	{
		i=Math.floor((currClipPosition/clipDuration)*numSlicesInProgressBar);
		//alert('updateProgressBar = ' + Math.floor((currClipPosition/clipDuration) * 100) + '\n' + i);
		for (p=0; p<numSlicesInProgressBar; p++)
		{
			if (p<i)
			{
				eval("document.img" + p + ".src=fullBarImg.src");
			}
			else
			{
				eval("document.img" + p + ".src=emptyBarImg.src");
			}
		}
	}
		
	//update the play button
	updatePlayButton();

	//update again in another x second
	setTimeout("updateProgressBar()",1000);
}

function CheckPlayMode()
{
	if (document.getElementById("playMode") == null)
		running = false;
	else
	{
		playMode = document.getElementById("playMode").value;
		if (playMode == 'playlist')
		{
			formName = document.getElementById("formName").value;
			document.forms[formName].action = document.getElementById("nextVideoUrl").value;
			document.forms[formName].submit();
		}
		else
			running = false;
	}
	//currClipPosition = 0;
}
function SetPlayLocationPercent(Percent)
{
	if (running)
	{
		clipDuration = Math.floor(MediaPlayer1.Duration);
		
		NewClipPosition =  Math.floor(clipDuration * (Percent/100));
		MediaPlayer1.CurrentPosition = NewClipPosition;
		updateProgressBar();
	}
}

function updatePlayButton()
{
	if (running)
	{
		document.playControlButton.src=pauseImg.src;
	}
	else
	{
		document.playControlButton.src=playImg.src;
	}
}

//Handle the rewind button
function BtnRew_OnClick()
{
	if (running)
	{
		if (MediaPlayer1.MarkerCount>0)
		{
			//handle the case where the video contains markers
			if (MediaPlayer1.CurrentMarker > 1)
				MediaPlayer1.CurrentMarker = MediaPlayer1.CurrentMarker - 1;
			else
				MediaPlayer1.CurrentMarker = 1;
		}
		else
		{
		    //handle pure video
		    var currpos  = MediaPlayer1.CurrentPosition;
		    if (currpos > deltaFFRew)
			  MediaPlayer1.CurrentPosition = currpos - deltaFFRew;
		    else
			  MediaPlayer1.CurrentPosition = 0;
		}
		updateProgressBar();
	}
}

//Handle the fast forward button
function BtnFF_OnClick()
{
	if (running)
	{
		if (MediaPlayer1.MarkerCount>0)
		{
			//handle the case where the video contains markers
			if (MediaPlayer1.CurrentMarker<MediaPlayer1.MarkerCount)
				MediaPlayer1.CurrentMarker = MediaPlayer1.CurrentMarker + 1
		}
		else
		{
			//handle pure video
			var currpos  = MediaPlayer1.CurrentPosition;
			var duration = MediaPlayer1.Duration;

			if ((duration-currpos) > deltaFFRew)
			   MediaPlayer1.CurrentPosition = currpos + deltaFFRew;
			else
			   MediaPlayer1.CurrentPosition = duration-1;
		}
		updateProgressBar();
	}
}

//Handle the play / pause button
function BtnPlayPause_OnClick()
{
	if (running)
	{
		running = false;
		currClipPosition = MediaPlayer1.CurrentPosition;
		MediaPlayer1.Pause();
	}
	else
	{
		running = true;
		MediaPlayer1.Play();
	}
	updatePlayButton();
}

//Handle the stop button
function BtnStop_OnClick()
{
	if (running)
	{
		running = false;
		currClipPosition = 0;
		MediaPlayer1.CurrentPosition=0;
		MediaPlayer1.Stop();
		MediaPlayer1.FileName = "";
		updatePlayButton();
	}
}

//Handle the full screen video button
function BtnFullScreen_OnClick()
{
	MediaPlayer1.DisplaySize=3
}

//Handle the volume up command
function BtnVolumeUp_OnClick()
{
	if (MediaPlayer1.Volume > -1000)
		MediaPlayer1.Volume = 0;
	else
		MediaPlayer1.Volume += 1000;
}

//Handle the volume down
function BtnVolumeDown_OnClick()
{
	if (MediaPlayer1.Volume > -9000)
		MediaPlayer1.Volume -= 1000;
}

//Scroll thumbnails up
function scrollThumbsDown()
{	
	thumbDiv = document.getElementById("thumbnailPreview");
	if (thumbDiv != null)
	{
		if ( (thumbDiv.scrollTop + 70) < thumbDiv.scrollHeight)
			thumbDiv.scrollTop = thumbDiv.scrollTop + 70;
		else
			thumbDiv.scrollTop = thumbDiv.scrollHeight - 70;
	}
}

//Scroll thumbnailes down
function scrollThumbsUp()
{
	thumbDiv = document.getElementById("thumbnailPreview");
	
	if (thumbDiv != null)
	{
		if (thumbDiv.scrollTop >= 70)
			thumbDiv.scrollTop = thumbDiv.scrollTop - 70;
		else 
			thumbDiv.scrollTop = 0;
	}
}


function BtnMute_OnClick()
{
	if (running) {
		if (MediaPlayer1.Volume <= -9000)
			MediaPlayer1.Volume = 0;
		else
			MediaPlayer1.Volume = -9000;
	}
	updateMuteButton();	
}

function updateMuteButton()
{
	if (document.buttonSoundMute.src==muteOvrImg.src)
		document.buttonSoundMute.src=muteImg.src;
	else
		document.buttonSoundMute.src=muteOvrImg.src;
}

//Return current location in mins / secs of track
function currPos() 
{
	if (running)
	{
	//	return "" & (MediaPlayer1.CurrentPosition \ 60) & ":" & Format(Int(MediaPlayer1.CurrentPosition Mod 60), "00");
	}
	return "";
}

function duration() 
{
	if (running)
	{
	//	return "" & (MediaPlayer1.SelectionEnd \ 60) & ":" & Format(Int(MediaPlayer1.SelectionEnd Mod 60), "00");
	}
}



//////////////////

// This script determines correct code required to embed MEDIA files 
// for a large number of browsers, including AOL and WebTV
// Windows Media Player is required and always used, except for WebTV
// Written by Les Gorven, http://midistudio.com/ 
// Ver. 3.0  Last Updated: January 17, 2006


function VPplayMedia(mediaURL,rpt,height,width) {

	var mediaURL,rpt,height,width
	
	if (VPGetBrowser() == "Netscape") 
		VPembedMPlayer(mediaURL,rpt,height,width);  
	if (VPGetBrowser() == "IE") 
		VPembedIEobject(mediaURL,rpt,height,width);
	if (navigator.appName.substring(0,5) == "WebTV")
		VPembedSource(mediaURL,rpt,height,width)
}

function VPembedSource(mediaURL,rpt,height,width) {

    var CodeGen = ""
    var mediaURL,rpt,height,width
 		 	
	CodeGen = '<embed src="' + mediaURL + '"' + '\n' ;
	CodeGen += ' height=' + height + ' width=' + width + ' autostart="true"' + '\n'
	CodeGen += ' LOOP=' + rpt + '>'
	 
    document.write(CodeGen)
}

function VPembedMPlayer(mediaURL,rpt,height,width)	{

	var CodeGen = "" 
	var mediaURL,rpt,height,width
			 	
	CodeGen = '<embed type="application/x-mplayer2" ' + '\n' ;
	CodeGen = CodeGen + ' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ' + '\n' ;
 	CodeGen = CodeGen + 'Name="MediaPlayer1" ' + 'src="' + mediaURL + '" ' + '\n' ;
 	CodeGen = CodeGen + 'autoStart=1 ' ;
	if ((height == 24) && (width == 299)) 
		CodeGen = CodeGen + 'ShowStatusBar=1 '; 
	if ((height >= 50) && (width >= 200)) 
		CodeGen = CodeGen + 'ShowStatusBar=1 '; 
	if ((height <= 49) && (width != 299))
		CodeGen = CodeGen + 'ShowStatusBar=0 '; 
	
	CodeGen = CodeGen + 'playCount=' + rpt + ' ' ;
	CodeGen = CodeGen + 'volume=-1 ' ;
	CodeGen = CodeGen + 'HEIGHT=' + height + ' WIDTH=' + width + '>'

	document.write(CodeGen)
}

function VPembedIEobject(mediaURL,rpt,height,width){

	var CodeGen = "" 
	var mediaURL,rpt,height,width

	CodeGen = '<object id=Player' + '\n' ;
	CodeGen += 'codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902' + '\n' ;
	CodeGen += 'type=application/x-oleobject height=' + height + ' width=' + width + '\n' ;
	CodeGen += ' standby="Loading Microsoft? Windows? Media Player components..." ' + '\n' ;
	CodeGen += 'classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"> ' + '\n' ;
	CodeGen += '<param NAME="Filename" VALUE="' + mediaURL + '">' + '\n' ;
	if ((height == 24) && (width == 299)) 
		CodeGen += '<param NAME="ShowStatusBar" VALUE= "true">';
	if ((height >= 50) && (width >= 200)) 
		CodeGen += '<param NAME="ShowStatusBar" VALUE= "true">'; 
	if ((height <= 49) && (width != 299))
		CodeGen += '<param NAME="ShowStatusBar" VALUE= "false"> ';
	
	CodeGen += '<param NAME="autoStart" VALUE="true"><param NAME="Volume" VALUE="-1">' + '\n' ;
	CodeGen += '<param NAME="playCount" VALUE=' + rpt + '></object>'
	
	document.write(CodeGen)
}

function VPGetBrowser()
{
   var agt=navigator.userAgent.toLowerCase();
   if( ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) )
       return "IE";
   else if( ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
         && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
         && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)) )
       return "Netscape";
   else
       return "unknown";
}


//window.onload=initializeProgressBar

//-->
