//<!-- PTV Cache: ptvche06/10.2.53.203 Mon, 21 May 2007 18:42:22 GMT -->
var PLAY = '<img src="/images/video/play.gif" alt="Play/Pause" height="25" width="36" />';
var PAUSE = '<img src="/images/video/pause.gif" alt="Pause" height="25" width="36" />';
var STOP = '<img src="/images/video/stop.gif" alt="Stop" height="25" width="36" />';
var REWIND = '<img src="/images/video/rewind.gif" alt="Rewind" height="25" width="36" />';
var FFORWARD = '<img src="/images/video/forward.gif" alt="Fast forward" height="25" width="36" />';
var FULL_SCREEN = '<img src="/images/video/fullscreen.gif" alt="Full screen" height="25" width="36" />';
var DOWNLOAD = '<img src="/images/video/download.gif" alt="Download" height="34" width="45" />';
var POPUP = '<img src="/images/video/popup.gif" alt="Download" height="34" width="41" />';
var mediaPlayers = [];
var agent = navigator.userAgent.toLowerCase();
var IS_MAC = agent.indexOf('mac') >= 0;
var IS_IE  = ((agent.indexOf('msie') != -1) && (agent.indexOf('opera') == -1));
var ADVERT_BANDWIDTH_HIGH = 500;
var ADVERT_BANDWIDTH_MEDIUM = 500;
var ADVERT_BANDWIDTH_LOW = 250;

function isPluginInstalled(pluginName) {
	var installed = false;
	if (navigator.plugins && navigator.plugins.length) {
		for (var ii = 0; ii < navigator.plugins.length; ++ii) {
			if (navigator.plugins[ii].name.indexOf(pluginName) >= 0) {
				installed = true;
				break;
			}
		}
	}
	return installed;
}


// Below was formatted from original source code on old site
// --
function MediaPlayer ( hiSource, mediumSource, loSource, allowDownload, audioStream, width, height, holdingImage, autoStart, parentElement, showStatus, playCount, displayAdvertising, externalControls ) { 
	if ( holdingImage ) {
		var img = new Image ( );
		img.src = holdingImage;
	}
	
	this.getDownloadPath = function ( source ) { 
		if ( source.indexOf ( "/page/media/0,,~,00.asx?path=" ) >= 0 ) {
			source = unescape ( source );
			source = this.decode ( source.substring ( "/page/media/0,,~,00.asx?path=".length ) );
		}
		source = source.replace ( "mms:", "http:" );
		source = source.replace ( "video\.premiumtv\.co\.uk", "avdownload\.premiumtv\.co\.uk:8129" );
		return source;
	};
	
	
	this.decode = function ( inString ) { 
		var alphabet = "abcdefghijklmnopqrstuvwxyz";
		var outString = "";
		for ( var ii = 0; ii < inString.length; ++ ii ) {
			var charact = inString.charAt ( ii );
			var isUpper = ( charact.toUpperCase ( ) == charact );
			charact = charact.toLowerCase ( );
			var charPosition = alphabet.indexOf ( charact );
			if ( charPosition >= 0 ) {
				charact = alphabet.charAt ( ( charPosition + ( alphabet.length / 2 ) ) % alphabet.length );
				if ( isUpper ) {
					charact = charact.toUpperCase ( );
				}
			}
			outString += charact;
		}
		return outString;
	};
	
	
	this.getAdvertisingPath = function ( path ) { 
		var adPath = path;
		if ( "/" == path.substring ( 0, 1 ) ) {
			path = SITE_URL + path;
		}
		if ( window.adStream ) {
			adPath = window.adStream + escape ( path ) + "&format=Video-Windows-" + this.getAdvertBandwidth ( path ) + "-480x360" + window.adStreamTail + ( window.adAttributes ? "&attr=" + window.adAttributes : "" );
		}
		return adPath;
	};
	
	
	this.getPlayState = function ( ) { 
		var stateText = "";
		if ( document[this.name] ) {
			var state = document[this.name].playState;
			switch ( state ) {
				case 0:
					stateText += "Ready";
					break;
				case 1:
					stateText += "Stopped";
					break;
				case 2:
					stateText += "Paused";
					break;
				case 3:
					stateText += "Playing";
					break;
				case 4:
					stateText += "Fast Forward";
					break;
				case 5:
					stateText += "Rewind";
					break;
				case 6:
					stateText += "Buffering";
					break;
				case 7:
					stateText += "Waiting";
					break;
				case 8:
					stateText += "End";
					break;
				case 9:
					stateText += "Connecting";
					break;
				case 10:
					stateText += "Ready";
					break;
				default:
					stateText += "";
					break;
			}
		}
		return stateText;
	};
	
	
	this.showPlayState = function ( ) { 
		var div = document.getElementById ( this.name + "playerStatus" );
		if ( div ) {
			div.innerHTML = this.getPlayState ( );
		}
		return;
	};
	
	
	this.getAdvertBandwidth = function ( currentSource ) { 
		var advertBandwidth = ADVERT_BANDWIDTH_LOW;
		if ( currentSource == this.hiSource ) {
			advertBandwidth = ADVERT_BANDWIDTH_HIGH;
		}
		else if ( currentSource == this.mediumSource ) {
			advertBandwidth = ADVERT_BANDWIDTH_MEDIUM;
		}
		return advertBandwidth;
	};
	
	
	this.setSources = function ( hiSource, mediumSource, loSource, renderNow ) { 
		if ( hiSource || mediumSource || loSource ) {
			if ( renderNow ) {
				this.stop ( );
			}
			this.hiSource = "";
			this.hiDownload = "";
			this.mediumSource = "";
			this.mediumDownload = "";
			this.loSource = "";
			this.lowDownload = "";
			if ( hiSource ) {
				this.hiSource = hiSource;
				if ( allowDownload ) {
					this.hiDownload = this.getDownloadPath ( this.hiSource );
				}
				if ( this.displayAdvertisting ) {
					this.hiSource = this.getAdvertisingPath ( hiSource );
				}
				this.currentSource = this.hiSource;
			}
			if ( mediumSource ) {
				this.mediumSource = mediumSource;
				if ( allowDownload ) {
					this.mediumDownload = this.getDownloadPath ( this.mediumSource );
				}
				if ( this.displayAdvertisting ) {
					this.mediumSource = this.getAdvertisingPath ( mediumSource );
				}
				this.currentSource = this.mediumSource;
			}
			if ( loSource ) {
				this.loSource = loSource;
				if ( allowDownload ) {
					this.loDownload = this.getDownloadPath ( this.loSource );
				}
				if ( this.displayAdvertisting ) {
					this.loSource = this.getAdvertisingPath ( loSource );
				}
				this.currentSource = this.loSource;
			}
			this.currentSource = this.loSource;
			var useLowestQualityVideo = false;
			if ( ! useLowestQualityVideo ) {
				this.currentSource = this.hiSource;
			}
			var quality = "HIGH";
			if ( this.hiSource && ( "HIGH" == quality || ! this.currentSource ) ) {
				this.currentSource = this.hiSource;
			}
			else if ( this.mediumSource && ( "MEDIUM" == quality || ! this.currentSource ) ) {
				this.currentSource = this.mediumSource;
			}
			else if ( this.loSource && ( "LOW" == quality || ! this.currentSource ) ) {
				this.currentSource = this.loSource;
			}
			if ( renderNow ) {
				this.rerender ( );
			}
		}
		return;
	};
	
	
	var CONTROLS_HEIGHT = 45;
	var ACTIVEX_PLAYER_NAME = "WMPlayer.OCX.7";
	if ( window.mediaCounter ) {
		++ window.mediaCounter;
	}
	else {
		window.mediaCounter = 1;
	}
	
	this.height = height;
	this.width = width;
	this.name = "mediaPlayer" + window.mediaCounter;
	this.holdingImage = holdingImage;
	this.holdingImageDisplayed = false;
	this.autoStart = autoStart;
	this.allowDownload = allowDownload;
	this.showStatus = showStatus;
	this.playCount = playCount ? playCount : 1;
	this.displayAdvertisting = displayAdvertising;
	this.externalControls = externalControls;
	this.currentSource = audioStream;
	this.setSources ( hiSource, mediumSource, loSource, false );
	window.mediaPlayers[window.mediaCounter] = this;
	this.installed = false;
	if ( window.ActiveXObject || ( window.GeckoActiveXObject && isPluginInstalled ( "ActiveX" ) ) ) {
		var player = null;
		try {
			if ( window.ActiveXObject && agent.indexOf ( 'win' ) != - 1 ) {
				player = new ActiveXObject ( ACTIVEX_PLAYER_NAME );
			}
			else {
				player = new GeckoActiveXObject ( ACTIVEX_PLAYER_NAME );
			}
		}
		catch ( error ) { }
		if ( player ) {
			this.installed = true;
			parseFloat ( player.versionInfo );
			this.version = parseFloat ( player.versionInfo );
			if ( this.version.toString ( ) . length == 1 ) {
				this.version += '.0';
			}
		}
	}
	else {
		this.installed = isPluginInstalled ( "Windows Media" );
	}
	
	
	this.atLeastVersion = function ( version ) { 
		return this.installed && parseInt ( this.version ) >= version;
	};
	
	
	this.stop = function ( ) { 
		if ( ! this.holdingImageDisplayed ) {
			if ( this.atLeastVersion ( 7 ) ) {
				var controls = document[this.name].controls;
				if ( controls.isAvailable ( "stop" ) ) {
					controls.stop ( );
				}
			}
			else {
				document.getElementById ( "container" + this.name ) . innerHTML = this.renderV6Player ( false, this.width, this.height );
			}
			if ( this.holdingImage ) {
				this.autoStart = false;
				this.rerender ( );
			}
		}
		return;
	};
	
	
	this.play = function ( ) { 
		this.clearHoldingImage ( );
		if ( this.atLeastVersion ( 7 ) ) {
			var controls = document[this.name].controls;
			if ( controls.isAvailable ( "play" ) ) {
				controls.play ( );
			}
			else if ( controls.isAvailable ( "pause" ) ) {
				controls.pause ( );
			}
			if ( this.holdingImage ) {
				this.displayHoldingImageAtEndOfVideo ( );
			}
		}
		else {
			if ( IS_IE && ! IS_MAC ) {
				document[this.name].Rate = 1;
				document[this.name].Play ( );
			}
			else {
				document.getElementById ( "container" + this.name ) . innerHTML = this.renderV6Player ( true, this.width, this.height );
			}
		}
		return;
	};
	
	
	this.displayHoldingImageAtEndOfVideo = function ( ) { 
		var playState = this.getPlayState ( );
		if ( playState ) {
			if ( "Stopped" == playState && this.holdingImage && ! this.holdingImageDisplayed ) {
				this.stop ( );
			}
			else if ( "Stopped" != playState ) {
				setTimeout ( "window.mediaPlayers[" + window.mediaCounter + "].displayHoldingImageAtEndOfVideo()", 100 );
			}
		}
		return;
	};
	
	
	this.pause = function ( ) { 
		if ( this.atLeastVersion ( 7 ) ) {
			if ( document[this.name] ) {
				var controls = document[this.name].controls;
				if ( controls && controls.isAvailable ( "pause" ) ) {
					controls.pause ( );
				}
			}
		}
		else {
			if ( IS_IE && ! IS_MAC ) {
				document[this.name].Rate = 1;
				document[this.name].Pause ( );
			}
			else {
				document.getElementById ( "container" + this.name ) . innerHTML = this.renderV6Player ( true, this.width, this.height );
			}
		}
		return;
	};
	
	
	this.setVolume = function ( volume ) { 
		if ( ! this.holdingImageDisplayed && this.atLeastVersion ( 7 ) ) {
			var settings = document[this.name].settings;
			if ( settings ) {
				settings.volume = parseInt ( volume );
			}
		}
		return;
	};
	
	
	this.getVolume = function ( volume ) { 
		var volume = null;
		if ( ! this.holdingImageDisplayed && this.atLeastVersion ( 7 ) ) {
			var settings = document[this.name].settings;
			if ( settings ) {
				volume = settings.volume;
			}
		}
		return volume;
	};
	
	
	this.fastForward = function ( ) { 
		if ( this.holdingImageDisplayed ) {
			this.clearHoldingImage ( );
			this.play ( );
			setTimeout ( "window.mediaPlayers[" + window.mediaCounter + "].fastForward()", 1000 );
		}
		else {
			if ( this.atLeastVersion ( 7 ) ) {
				var controls = document[this.name].controls;
				if ( controls.isAvailable ( "fastForward" ) ) {
					controls.fastForward ( );
				}
			}
			else {
				if ( document[this.name].Rate > 1 ) {
					document[this.name].Rate = 1;
				}
				else {
					document[this.name].Rate = 2;
				}
			}
		}
		return;
	};
	
	
	this.rewind = function ( ) { 
		if ( ! this.holdingImageDisplayed ) {
			if ( this.atLeastVersion ( 7 ) ) {
				var controls = document[this.name].controls;
				if ( controls.isAvailable ( "fastReverse" ) ) {
					controls.fastReverse ( );
				}
			}
			else {
				if ( document[this.name].AllowScan ) {
					document[this.name].Rate = - 2;
				}
				else {
					document[this.name].CurrentPosition = 0;
				}
				document[this.name].Play ( );
			}
		}
		return;
	};
	
	
	this.enableFullScreen = function ( ) { 
		this.clearHoldingImage ( );
		if ( this.atLeastVersion ( 7 ) ) {
			try {
				var controls = document[this.name].controls;
				if ( controls.isAvailable ( "play" ) ) {
					this.play ( );
				}
				document[this.name].fullScreen = true;
			}
			catch ( error ) {
				setTimeout ( "window.mediaPlayers[" + window.mediaCounter + "].enableFullScreen()", 100 );
			}
		}
		else if ( IS_MAC ) {
			var width = screen.width;
			var height = screen.height;
			win = window.open ( "", "fullscreen", "left=0,top=0,width=" + width + ",height=" + height + ",scrollbars=no" );
			this.stop ( );
			if ( win.document.body ) {
				win.document.open ( );
				win.document.write ( "<html>" + "<head>" + "<title>Full screen video</title>" + "<style>body {margin:0px;padding:0px;}</style>" + "</head>" + "<body>" + this.renderV6Player ( true, width, height ) + "</body>" + "</html>" );
				win.document.close ( );
				win.document.title = "Full screen video";
			}
		}
		else if ( IS_IE ) {
			document[this.name].DisplaySize = 3;
			document[this.name].Play ( );
		}
		return;
	};
	
	
	this.rerender = function ( ) { 
		var wrapper = document.getElementById ( "mediaWrapper" + this.name );
		var player = document.getElementById ( this.name );
		if ( player ) {
			player.id = "";
			player.style.display = "none";
		}
		wrapper.innerHTML = this.renderAll ( );
		if ( this.autoStart ) {
			this.displayHoldingImageAtEndOfVideo ( );
		}
		return;
	};
	
	
	this.renderV6Player = function ( autostart, width, height ) { 
		return "<object id='" + this.name + "' " + "classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 " + "codebase=http://activex.microsoft.com/" + "activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715 " + "standby='Loading Microsoft Windows Media Player components...' " + "type='application/x-oleobject' width='" + width + "' height='" + height + "'>" + "<param name='URL' value='" + this.currentSource + "'>" + "<param name='autostart' value='" + autostart + "'>" + "<param name='showcontrols' value='0'>" + "<param name='enableContextMenu' value='0'>" + "<param name='windowlessvideo' value='true'>" + "<param name='playCount' value='" + this.playCount + "'>" + "<embed type='application/x-mplayer2'" + " pluginspage='http://www.microsoft.com/windows/windowsmedia/'" + " src='" + this.currentSource + "'" + " name='" + this.name + "'" + " ShowControls=1" + " ShowDisplay=0" + " ShowStatusBar=0" + " EnableContextMenu=0" + " DisplaySize=" + ( true ? 4 : 0 ) + " AutoStart=" + ( autostart ? 1 : 0 ) + " PlayCount=" + this.playCount + " Controller=0" + " width=" + width + " height=" + height + ">" + "</embed>" + "</object>";
	};
	
	
	this.renderV7Player = function ( autoStart, width, height ) { 
		return "<object id='" + this.name + "'" + " classid=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" + " standby='Loading Microsoft Windows Media Player components...'" + " type='application/x-oleobject' width='" + width + "' height='" + height + "'>" + "<param name='url' value='" + this.currentSource + "'>" + "<param name='AutoStart' value='" + autoStart + "'>" + "<param name='PlayCount' value='" + this.playCount + "'>" + "<param name='windowlessvideo' value='true'>" + "<param name='EnableContextMenu' value='0'>" + "<param name='uiMode' value='none'>" + "<param name='stretchToFit' value='true'>" + "</object>";
	};
	
	
	this.clearHoldingImage = function ( ) { 
		if ( this.holdingImageDisplayed && this.atLeastVersion ( 7 ) ) {
			document.getElementById ( "container" + this.name ) . innerHTML = this.renderV7Player ( this.autoStart, this.width, this.height );
		}
		this.holdingImageDisplayed = false;
		return;
	};
	
	
	this.changeSource = function ( source, downloadSource ) { 
		this.currentSource = source;
		var popupLink = document.getElementById ( "popup" + this.name );
		if ( popupLink ) {
			popupLink.href = this.currentSource;
		}
		var downloadLink = document.getElementById ( "download" + this.name );
		if ( downloadLink ) {
			downloadLink.href = downloadSource;
		}
		if ( ! this.holdingImageDisplayed ) {
			this.stop ( );
			document.getElementById ( "container" + this.name ) . innerHTML = this.atLeastVersion ( 7 ) ? this.renderV7Player ( ! this.holdingImageDisplayed, this.width, this.height ) : this.renderV6Player ( ! this.holdingImageDisplayed, this.width, this.height );
			this.play ( );
		}
		return;
	};
	
	
	this.renderControls = function ( ) { 
		var controlsHtml = "";
		if ( this.currentSource && this.atLeastVersion ( 7 ) ) {
			controlsHtml += "<div class='mediaButtons' " + ( ( this.externalControls ) ? "style='display:none;'" : "" ) + ">";
			controlsHtml += "<span class='controlButtons'>";
			controlsHtml += "<a class='rewindButton' href='#rewind' onclick='window.mediaPlayers[" + window.mediaCounter + "].rewind();return false;'><span>" + REWIND + "</span></a>" + "<a class='playButton' href='#play' onclick='window.mediaPlayers[" + window.mediaCounter + "].play();return false;'><span id='play" + this.name + "'>" + PLAY + "</span></a>" + "<a class='stopButton' href='#stop' onclick='window.mediaPlayers[" + window.mediaCounter + "].stop();return false;'><span>" + STOP + "</span></a>" + "<a class='fastForwardButton' href='#fastForward' onclick='window.mediaPlayers[" + window.mediaCounter + "].fastForward();return false;'><span>" + FFORWARD + "</span></a>" + "</span>";
		}
		controlsHtml += "<span class='playerButtons'>";
		if ( this.currentSource && this.atLeastVersion ( 7 ) || IS_MAC ) {
			controlsHtml += "<a class='fullScreenButton' href='#stop'" + "   onclick='window.mediaPlayers[" + window.mediaCounter + "].enableFullScreen();return false;'>" + "<span>" + FULL_SCREEN + "</span></a>";
		}
		if ( this.currentSource ) {
			controlsHtml += "<a class='popupButton' id='popup" + this.name + "' href='" + this.currentSource + "'><span>" + POPUP + "</span></a>";
		}
		if ( this.allowDownload ) {
			controlsHtml += "<a id='download" + this.name + "' class='downloadButton' href='" + ( ( this.hiDownload && ( this.hiSource == this.currentSource ) ) ? this.hiDownload : this.loDownload ) + "' oncontextmenu='if (!event.stopPropagation) event.cancelBubble=true;'><span>" + DOWNLOAD + "</span></a>";
		}
		controlsHtml += "</span>";
		var streamsAvailable = ( this.loSource ? 1 : 0 ) + ( this.mediumSource ? 1 : 0 ) + ( this.hiSource ? 1 : 0 );
		if ( streamsAvailable > 1 ) {
			controlsHtml += "<div class='mediaQuality'>";
			if ( this.loSource ) {
				controlsHtml += "<input type='radio' name='" + this.name + "quality'" + " onclick='window.mediaPlayers[" + window.mediaCounter + "]" + ".changeSource(\"" + this.loSource + "\", \"" + this.loDownload + "\");" + "SetCookie(\"videoQuality\",\"LOW\");' " + ( this.loSource == this.currentSource ? "checked='true'" : "" ) + ">Low";
			}
			if ( this.mediumSource ) {
				controlsHtml += "<input type='radio' name='" + this.name + "quality'" + " onclick='window.mediaPlayers[" + window.mediaCounter + "]" + ".changeSource(\"" + this.mediumSource + "\", \"" + this.mediumDownload + "\");" + "SetCookie(\"videoQuality\",\"MEDIUM\");' " + ( this.mediumSource == this.currentSource ? "checked='true'" : "" ) + ">Medium";
			}
			if ( this.hiSource ) {
				controlsHtml += "<input type='radio' name='" + this.name + "quality'" + " onclick='window.mediaPlayers[" + window.mediaCounter + "]" + ".changeSource(\"" + this.hiSource + "\", \"" + this.hiDownload + "\");" + "SetCookie(\"videoQuality\",\"HIGH\");' " + ( this.hiSource == this.currentSource ? "checked='true'" : "" ) + ">High";
			}
			controlsHtml += "</div>";
		}
		return controlsHtml;
	};
	
	
	this.renderAll = function ( ) { 
		var playerHtml = "<div class='mediaPlayer'>" + "<div id='container" + this.name + "'>";
		if ( this.holdingImage && ! this.autoStart && ( this.atLeastVersion ( 7 ) || ! IS_IE || IS_MAC ) ) {
			this.holdingImageDisplayed = true;
			var imageHtml = "<img src='" + holdingImage + "' " + "width='" + width + "' " + "height='" + height + "' ";
			if ( window.holdingImageLink ) {
				playerHtml += "<a href='" + window.holdingImageLink + "'>" + imageHtml + "></a>";
			}
			else {
				playerHtml += ( imageHtml + "onclick='window.mediaPlayers[" + window.mediaCounter + "].play()'>" );
			}
		}
		else {
			if ( this.currentSource ) {	
				if ( this.atLeastVersion ( 7 ) ) {
					playerHtml += this.renderV7Player ( this.autoStart, this.width, this.height );
				}
				else {
					playerHtml += this.renderV6Player ( this.autoStart, this.width, this.height );
				}
			}
		}
		playerHtml += "</div>";
		//playerHtml += this.renderControls ( );
		if ( this.showStatus && this.atLeastVersion ( 7 ) ) {
			playerHtml += "<div class='playerStatus' id='" + this.name + "playerStatus'><div>";
			setInterval ( "window.mediaPlayers[" + window.mediaCounter + "].showPlayState()", 200 );
		}
		playerHtml += "</div>";
		return playerHtml;
	};
	
	var gvolume = 100;
	this.height = this.atLeastVersion ( 7 ) ? height : height + CONTROLS_HEIGHT;
	var html = "<div id='mediaWrapper" + this.name + "' class='mediaWrapper'>" + this.renderAll ( ) + "</div>";
	if ( parentElement ) {
		parentElement.innerHTML = html;
	}
	else {
		//alert(html);
		document.write(html);
	}
	if ( this.autoStart ) {
		this.displayHoldingImageAtEndOfVideo ( );
	}
}


// -- Below here was originally in the HTML document
// -- (Section 2)
var rewindButtonOff = new Image();
rewindButtonOff.src = "/images/video/rewind.gif";
rewindButtonOff.alt = "Rewind"; 
var rewindButtonOn = new Image();
rewindButtonOn.src = rewindButtonOff.src;
rewindButtonOn.alt = rewindButtonOff.alt;        
rewindButtonOn.src = "/images/video/rewind_over.gif";
rewindButtonOn.alt = "Rewind";
var rewindButtonClick = new Image();
rewindButtonClick.src = rewindButtonOff.src;
rewindButtonClick.alt = rewindButtonOff.alt;        
rewindButtonClick.src = "/images/video/rewind_over.gif";
rewindButtonClick.alt = "Rewind";
			
var playButtonOff = new Image();
playButtonOff.src = "/images/video/play.gif";
playButtonOff.alt = "Play";
var playButtonOn = new Image();
playButtonOn.src = playButtonOff.src;
playButtonOn.alt = playButtonOff.alt;        	
playButtonOn.src = "/images/video/play_over.gif";
playButtonOn.alt = "Pause";
var playButtonClick = new Image();
playButtonClick.src = playButtonOff.src;
playButtonClick.alt = playButtonOff.alt;        
playButtonClick.src = "/images/video/play_over.gif";
playButtonClick.alt = "Play";
			
var pauseButtonOff = new Image();
pauseButtonOff.src = "/images/video/pause.gif";
pauseButtonOff.alt = "Pause";    
var pauseButtonOn = new Image();
pauseButtonOn.src = pauseButtonOff.src;
pauseButtonOn.alt = pauseButtonOff.alt;        
pauseButtonOn.src = "/images/video/pause_over.gif";
pauseButtonOn.alt = "Play";
var pauseButtonClick = new Image();
pauseButtonClick.src = pauseButtonOff.src;
pauseButtonClick.alt = pauseButtonOff.alt;        
pauseButtonClick.src = "/images/video/pause_over.gif";

pauseButtonClick.alt = "Pause";

var stopButtonOff = new Image();
stopButtonOff.src = "/images/video/stop.gif";
stopButtonOff.alt = "Stop";    
var stopButtonOn = new Image();
stopButtonOn.src = stopButtonOff.src;
stopButtonOn.alt = stopButtonOff.alt;        
stopButtonOn.src = "/images/video/stop_over.gif";
stopButtonOn.alt = "Stop";
var stopButtonClick = new Image();
stopButtonClick.src = stopButtonOff.src;
stopButtonClick.alt = stopButtonOff.alt;        
stopButtonClick.src = "/images/video/stop_over.gif";
stopButtonClick.alt = "Stop";

var fastForwardButtonOff = new Image();
fastForwardButtonOff.src = "/images/video/forward.gif";
fastForwardButtonOff.alt = "Fast Forward"; 
var fastForwardButtonOn = new Image();
fastForwardButtonOn.src = fastForwardButtonOff.src;
fastForwardButtonOn.alt = fastForwardButtonOff.alt;        
fastForwardButtonOn.src = "/images/video/forward_over.gif";
fastForwardButtonOn.alt = "Forward";
var fastForwardButtonClick = new Image();
fastForwardButtonClick.src = fastForwardButtonOff.src;
fastForwardButtonClick.alt = fastForwardButtonOff.alt;        
fastForwardButtonClick.src = "/images/video/forward_over.gif";
fastForwardButtonClick.alt = "Forward";

var volumeUpButtonOff = new Image();
volumeUpButtonOff.src = "/images/video/turn_up.gif";
volumeUpButtonOff.alt = "Up";    
var volumeUpButtonOn = new Image();
volumeUpButtonOn.src = volumeUpButtonOff.src;
volumeUpButtonOn.alt = volumeUpButtonOff.alt;        
volumeUpButtonOn.src = "/images/video/turn_up.gif";
volumeUpButtonOn.alt = "Volume Up";
var volumeUpButtonClick = new Image();
volumeUpButtonClick.src = volumeUpButtonOff.src;
volumeUpButtonClick.alt = volumeUpButtonOff.alt;        
volumeUpButtonClick.src = "/images/video/turn_up_over.gif";
volumeUpButtonClick.alt = "Volume Up";

var volumeDownButtonOff = new Image();
volumeDownButtonOff.src = "/images/video/turn_down.gif";
volumeDownButtonOff.alt = "Down";    
var volumeDownButtonOn = new Image();
volumeDownButtonOn.src = volumeDownButtonOff.src;
volumeDownButtonOn.alt = volumeDownButtonOff.alt;        
volumeDownButtonOn.src = "/images/video/turn_down.gif";
volumeDownButtonOn.alt = "Volume Down";
var volumeDownButtonClick = new Image();
volumeDownButtonClick.src = volumeDownButtonOff.src;
volumeDownButtonClick.alt = volumeDownButtonOff.alt;        
volumeDownButtonClick.src = "/images/video/turn_down_over.gif";
volumeDownButtonClick.alt = "Volume Down";
			
var buttonStates = [
	{id: "rewindButton", 
	off: ["pauseButton", "stopButton", "fastForwardButton" ]
	},
	{id: "playButton", 
	off: ["rewindButton", "stopButton", "fastForwardButton" ]
	},    
	{id: "pauseButton", 
	off: ["rewindButton", "stopButton", "fastForwardButton" ]
	},    
	{id: "stopButton", 
	off: ["rewindButton", "fastForwardButton", "pauseButton" ]
	},    
	{id: "fastForwardButton", 
	off: ["pauseButton", "stopButton", "rewindButton"]
	},
	{id: "lowQualityButton", 
	off: ["highQualityButton", "mediumQualityButton", "stopButton", "fastForwardButton", "rewindButton"]
	}, 
	{id: "mediumQualityButton", 
	off: ["highQualityButton", "lowQualityButton", "stopButton", "fastForwardButton", "rewindButton"]
	},       
	{id: "highQualityButton", 
	off: ["lowQualityButton", "mediumQualityButton", "stopButton", "fastForwardButton", "rewindButton"]
	},
	{id: "downloadButton", off: []}, 
	{id: "volumeUpButton", off: []}, 
	{id: "volumeDownButton", off: []}, 
	{id: "fullScreenButton", off: []}      
	];
	var onMouseUpTimeOut = 100;
	
	function mouseOver(e) 
	{
		e = e ? e : window.event;
		var target = e.target ? e.target : e.srcElement;
		if (target.tagName == "IMG") 
		{
			target.className = "mouseBeOnMe";
		}
		return;
	}
	
	function mouseOut(e) 
	{
		e = e ? e : window.event;
		var target = e.target ? e.target : e.srcElement;
		if (target.tagName == "IMG") 
		{
			target.className = "mouseBeOffMe";
		}
		return;
	}
	
	function mouseDown(e) 
	{
		e = e ? e : window.event;
		var target = e.target ? e.target : e.srcElement;
		if (target.tagName == "IMG") {
			target.className = "mouseBeDown";
			pressButton(target.id); 
		}
		return;
	}
			
	function mouseUp(e) 
	{
		e = e ? e : window.event;
		var target = e.target ? e.target : e.srcElement;
		if (target.tagName == "IMG") {
			target.className = "mouseBeUp";
			setTimeout('releaseButton(\'' + target.id +'\');',onMouseUpTimeOut);
		}
		return;
	}
	 
	function initControls() 
	{
		if (player) 
		{
			setPlayPauseButton();
			var controls = document.getElementById("atpMediaPlayerControls");
			controls.onmouseover = mouseOver;
			controls.onmousedown = mouseDown;
			controls.onmouseup = mouseUp;
			controls.onmouseout = mouseOut;
		}  
		return;       
	} 
	
	function pressButton(btnId) 
	{
		if (currentEventSource == null) 
		{
			currentEventSource = window.event.srcElement;
			var buttonImage = document.getElementById(btnId);
			if (buttonImage) 
			{
				buttonImage.src = eval(btnId + "Click").src;
				buttonImage.alt = eval(btnId + "Click").alt; 
				var buttonDescription = null;
				for (var ii = 0; ii < buttonStates.length; ii++) 
				{
					if (btnId == buttonStates[ii].id) 
					{
						buttonDescription = buttonStates[ii];
						break; 
					}
				}   
				if (buttonDescription) 
				{
					for (var jj = 0; jj < buttonDescription.off.length; ++jj) 
					{
						var buttonImage = document.getElementById(buttonDescription.off[jj]);
						if (buttonImage)
						{
							buttonImage.src = eval(buttonImage.id + "Off").src;
							buttonImage.alt = eval(buttonImage.id + "Off").alt;            
						}  
					}
				}
			}         
		}
	} 
	
	function releaseButton(btnId) 
	{
		if (currentEventSource != null && currentEventSource.id == btnId) 
		{
			var buttonImage = document.getElementById(btnId);
			if (buttonImage) 
			{
				buttonImage.src = eval(btnId + "On").src;
				buttonImage.alt = eval(btnId + "On").alt;
				if (buttonImage.id == "rewindButton") 
				{
					player.rewind();
				}
				else if (buttonImage.id == "playButton") 
				{
					player.play();
				}
				else if (buttonImage.id == "pauseButton") 
				{
					player.pause();
				} 
				else if (buttonImage.id == "stopButton") 
				{
					player.stop();
				} 
				else if (buttonImage.id == "fastForwardButton") 
				{
					player.fastForward();
				}
				else if (buttonImage.id == "volumeUpButton") 
				{
					volumeUp();
				}
				else if (buttonImage.id == "volumeDownButton") 
				{
					volumeDown();
				}
				setPlayPauseButton();
			}  
			currentEventSource = null;
		}  
	}
	    
	function setPlayPauseButton() 
	{
		var playerObject = document[player.name];
		var playPauseButton = (document.getElementById("playButton")?document.getElementById("playButton"):document.getElementById("pauseButton"));
		if (playerObject && playerObject.controls.isAvailable("pause")) 
		{
			playPauseButton.src = pauseButtonOff.src;
			playPauseButton.alt = pauseButtonOff.alt;
			playPauseButton.id = "pauseButton";
		}
		else 
		{
			playPauseButton.src = playButtonOff.src;
			playPauseButton.alt = playButtonOff.alt;
			playPauseButton.id = "playButton";
		}
	}
	
	
// -- (Section 3) --	
// -- *********** --



function initPlayer(){
//if ("undefined" != typeof player && player.atLeastVersion(7)){
	if( ! player.atLeastVersion(7) ){
		// ??
		return;
	}
	document.getElementById("atpMediaPlayerControls").style.display = "block";
	window.mediaPlayerContainer = document.getElementById("videoPlayer");
	window.slider = document.createElement("div");
	window.slider.id = "slider";
	window.sliderContainer = document.createElement("div");
	window.sliderContainer.appendChild(slider);
	window.sliderContainer.id = "sliderContainer";
	window.mediaPlayerContainer.appendChild(sliderContainer);
			
	window.sliderContainer.onmousedown = function (event) 
	{
		event = event ? event : window.event;
		player.dragging = true;
		sliderContainer.onmousemove = moveSlider;
		moveSlider(event);
		return;
	};
	
	window.sliderContainer.onselectstart = function() 
	{
		return false
	};
	
	window.document.onmouseup = function() 
	{
		player.dragging = false;
		sliderContainer.onmousemove = null;
	};

	setSlider();
	
	window.currentEventSource = null;
	//window.onload = function(){
		initControls();
	//}
}


	
/* -------- Following takes out Elapsed Time Display------
var elapsedTimeBox = document.createElement("span");
elapsedTimeBox.id = "elapsedTimeBox";
var totalTimeBox = document.createElement("span");
totalTimeBox.id = "totalTimeBox";
var timeBox = document.createElement("div");
timeBox.id = "timeBox";
timeBox.appendChild(elapsedTimeBox);
timeBox.appendChild(totalTimeBox);   
mediaPlayerContainer.appendChild(timeBox);
*/

function setSlider() 
{
	if (!player.dragging) 
	{
		
		try 
		{
			var playerObject = document[player.name];    
			var slider = document.getElementById("slider");
			if (playerObject.controls.currentPosition == 0) 
			{
				slider.style.marginLeft = 0;
				setTimeout("setPlayPauseButton()", 500);               
				document.getElementById("fastForwardButton").src = fastForwardButtonOff.src;
				document.getElementById("fastForwardButton").alt = fastForwardButtonOff.alt;
				document.getElementById("rewindButton").src = rewindButtonOff.src;
				document.getElementById("rewindButton").alt = rewindButtonOff.alt;
			}
			else 
			{
				var percentage = (playerObject.controls.currentPosition / playerObject.currentMedia.duration) * 100;                    
				var containerWidth = slider.parentNode.offsetWidth - slider.offsetWidth;  
				slider.style.marginLeft = Math.round(percentage * (containerWidth / 100));                      
			} 
			document.getElementById("elapsedTimeBox").innerHTML = playerObject.controls.currentPositionString;
			document.getElementById("totalTimeBox").innerHTML = 'Total Time: ' + formatSecondsToHHMMSS(playerObject.currentMedia.duration);
		}
		catch (error) { }
	}
	setTimeout("setSlider()", 1000);
	return;
}


function moveSlider(event) 
{
	event = event ? event : window.event;
	var slider = document.getElementById("slider");
	var offset;
	if (event.offsetX) 
	{
		offset = event.offsetX;
		if (event.srcElement.id == "slider") 
		{
			offset += parseInt(slider.style.marginLeft); 
		}
	}
	else
	{
		var pageScroll = getPageScroll();
		var coords = getCoordinates(slider.parentNode);
		offset = event.clientX - coords.x + pageScroll.x
	}
	offset -= slider.offsetWidth/2;
	var pixelMargin = Math.max(
	0,
	Math.min(offset, slider.parentNode.offsetWidth - slider.offsetWidth)
	);
	slider.style.marginLeft = pixelMargin;
	var playerObject = document[player.name];
	playerObject.controls.currentPosition = 
	(pixelMargin / (slider.parentNode.offsetWidth - slider.offsetWidth)) * 
	playerObject.currentMedia.duration;
	return;
} 

function volumeUp() 
{
	player.setVolume(Math.min(player.getVolume() + 10, 100));
	return;
}

function volumeDown() 
{
	player.setVolume(Math.max(player.getVolume() - 10, 0));
	return;
}

function getPageScroll()
{
	if (document.body.scrollTop != undefined) 
	{
		var ieBox = document.compatMode != "CSS1Compat";
		var cont = ieBox ? document.body : document.documentElement;
		return {x : cont.scrollLeft, y : cont.scrollTop};
	} 
	else
	{
		return {x : window.pageXOffset, y : window.pageYOffset};
	}
}

function getCoordinates(obj) 
{
	var x = 0;
	var y = 0;
	for (; obj.parentNode; obj = obj.parentNode) 
	{
		x += obj.offsetLeft
		y += obj.offsetTop;
	}
	return {x:x, y:y};
}
		
function formatSecondsToHHMMSS(seconds) 
{
	var intHours;
	var intMinutes;
	var intSeconds;
	var strHours="00";
	var strMinutes="00";
	var strSeconds="00";
	seconds=Math.floor(seconds); // round down to the nearest integer
	intHours=Math.floor(seconds/3600); // get hours (3600 seconds / hour)
	intMinutes=Math.floor(seconds/60); // get minutes (60 seconds / minite)
	intSeconds=Math.floor((seconds%60)); // get seconds (total seconds modulous 60)
	strHours=intHours;
	strMinutes=intMinutes;
	strSeconds=intSeconds;
	if (intSeconds < 10)
	strSeconds="0" + strSeconds;
	if (intMinutes < 10)
	strMinutes="0" + strMinutes;
	if (intHours < 10)
	strHours="0" + strHours;
	return strHours + ":" + strMinutes + ":" + strSeconds; // create time string
}

	
