// Declare isAdPlaying check variable to false
var isAdPlaying = false;
// Declare variables for Euphony homepages T1 Video
var tourT1PlayerReady = false;
var t1PlayerConfig = null;

/* Set CVP options via the url parameter. Options available are:
	cvpoption=adtest, Appends "AdTest" to the CVP context.
	cvpoption=adfree, Appends "AdFree" to the CVP context.
	cvpoption=cdnoff, Makes the references to the included JavaScript files relative for testing purposes.
	cvpoption=profile1, Set CVP profile to 1.
	cvpoption=profile2, Set CVP profile to 2.
	To use multiple CVP options at once, use the pipe character "|" to separate the values. For example: cvpoption=cdnoff|profile1.
*/
var urlCDNOption = 'http://i.cdn.turner.com/pgatour';
var urlContextOption = '';
var urlProfileOption = '';
if(window.location.search.match('cvpoption=([^&]*)')){
	var regexOption = new RegExp('cvpoption=([^&]*)');
	var tourCVPOption = regexOption.exec(window.location.search);
	if(tourCVPOption[1].match('adtest')){
		urlContextOption = 'AdTest';
	}
	else if(tourCVPOption[1].match('adfree')){
		urlContextOption = 'AdFree';
	}
	if(tourCVPOption[1].match('cdnoff')){
		urlCDNOption = '';
	}
	if(tourCVPOption[1].match('profile1')){
		urlProfileOption = '1';
	}
	else if(tourCVPOption[1].match('profile2')){
		urlProfileOption = '2';
	}
}

// Include all necessary JavaScript files.
document.write('<scr'+'ipt src='+'"'+urlCDNOption+'/.element/apps/cvp/4.0/js/cvp.js" type="text/javascript"'+'></scr'+'ipt>'); // CVP 2.0 JavaScript file version 2.7 minimized
document.write('<scr'+'ipt src='+'"'+urlCDNOption+'/.element/apps/cvp/4.0/js/cvpPages.js" type="text/javascript"'+'></scr'+'ipt>'); // JavaScript file with object containing all information for pages that use CVP.
document.write('<scr'+'ipt src='+'"'+urlCDNOption+'/.element/apps/cvp/4.0/js/cvpOmniture.js" type="text/javascript"'+'></scr'+'ipt>'); // JavaScript file with object containing Omniture function calls.

/* Object containing information about the current page CVP is being used on. This gets populated in the tourCVP.detectCVPPage() function. */
var currentCVPPage;

/* START - tourCVP object */
/* tourCVP object contains: site name, profile number, embed configuration, available players, and initialization functions. */
var tourCVP = {
	// Site name
	site: 'pgatour',
	
	// Profile number. May be set via URL parameter.
	profile: (urlProfileOption != '') ? urlProfileOption : '1',
	
	// Minimum required Flash version for CVP to get embedded
	minimumRequiredFlashVersion: '1.0.0',
	
	// General embed configuration
	embedConfig: {
		containerSwf : 'http://i.cdn.turner.com/pgatour/.element/apps/cvp/4.0/swf/cvp_main_container.swf',
		expressInstallSwf : 'http://i.cdn.turner.com/xslo/cvp/assets/flash/expressInstall.swf',
		options: {
			quality: 'high',
			bgcolor: '#000000',
			allowFullScreen: 'true', 
			allowScriptAccess: 'always',
			wmode: 'transparent'
		}
	},
	
	// Initialization function
	initialize: function(){
		tourCVP.loadExternalCVPObjects();
		tourCVP.detectCVPPage();
		tourCVP.buildCVPInstance();
	},
	
	// Load all external objects needed for CVP to work
	loadExternalCVPObjects: function(){
		tourCVP.pages = CVP_PAGES; // Load the object containing CVP page information
		tourCVP.omniture = CVP_OMNITURE; // Load the object containing the omniture content callback functions
	},
	
	// Function to detect which page user is on get page configurations
	detectCVPPage: function(){
		for(key in tourCVP.pages){
			if(tourCVP.pages[key][0].urlMatchStatement == true){
				tourCVP.createArrayOfObjects();
				currentCVPPage = tourCVP.pages[key];
				break;
			}
		}
	},
	
	// Dynamically creates array of objects for the current CVP page
	createArrayOfObjects: function(){
		if(tourCVP.pages[key][0].createArrayOfObjects){
			tourCVP.pages[key][0].createArrayOfObjects();
		}
	},
	
	// Build a CVP instance
	buildCVPInstance: function(){
		if(currentCVPPage != null){
			// Loops through the array of CVP object instances for the current page
			for(var instanceCount = 0; instanceCount < currentCVPPage.length; instanceCount++){
				tourCVP.setPlayerConfig(instanceCount);
				if(currentCVPPage != tourCVP.pages.homepage && currentCVPPage != tourCVP.pages.euphonyHomepage){
					//Initialize CVP instance
					window[currentCVPPage[instanceCount].playerInstanceName] = new CVP(currentCVPPage[instanceCount]);
					// Embed the CVP swf if a supplemental JavaScript file for the page hasn't already done so.
					if($(currentCVPPage[instanceCount].videoContainerId) && (CVP.swfobject.hasFlashPlayerVersion(tourCVP.minimumRequiredFlashVersion) || (navigator.userAgent.indexOf('iPad') != -1))){
						window[currentCVPPage[instanceCount].playerInstanceName].embedSWF(currentCVPPage[instanceCount].videoContainerId);
					}
					else{
						tourCVP.showFlashUpgradeSlate(instanceCount);
					}
				}
			}
		}
	},
	
	// Set the player configurations
	setPlayerConfig: function(instanceCount){
		currentCVPPage[instanceCount].id = tourCVP.players[currentCVPPage[instanceCount].player].id + instanceCount;
		currentCVPPage[instanceCount].width = tourCVP.players[currentCVPPage[instanceCount].player].width;
		currentCVPPage[instanceCount].height = tourCVP.players[currentCVPPage[instanceCount].player].height;
		currentCVPPage[instanceCount].context = tourCVP.players[currentCVPPage[instanceCount].player].context;
		if(typeof currentCVPPage[instanceCount].flashVars == 'undefined'){
			currentCVPPage[instanceCount].flashVars = new Object();
		}
		currentCVPPage[instanceCount].flashVars.context = (currentCVPPage[instanceCount].contextOverride != '') ? ((urlContextOption != '') && (currentCVPPage[instanceCount].contextOverride.indexOf(urlContextOption) == -1)) ? currentCVPPage[instanceCount].contextOverride + urlContextOption : currentCVPPage[instanceCount].contextOverride : currentCVPPage[instanceCount].context + urlContextOption;
		currentCVPPage[instanceCount].flashVars.autostart = (currentCVPPage[instanceCount].autostartOverride != '') ? currentCVPPage[instanceCount].autostartOverride : '';
		currentCVPPage[instanceCount].flashVars.site = tourCVP.site;
		currentCVPPage[instanceCount].flashVars.profile = tourCVP.profile;
		if(typeof currentCVPPage[instanceCount].contentId != 'undefined'){
			currentCVPPage[instanceCount].flashVars.contentId = currentCVPPage[instanceCount].contentId;
		}
		currentCVPPage[instanceCount].embed = tourCVP.embedConfig;
	},
	
	showFlashUpgradeSlate: function(instanceCount){
		var slate = document.createElement('img');
		slate.src = 'http://i.cdn.turner.com/pgatour/.element/apps/cvp/4.0/img/'+currentCVPPage[instanceCount].width+'x'+currentCVPPage[instanceCount].height+'_flash_slate.jpg';
		slate.setAttribute('onclick','window.open("http://get.adobe.com/flashplayer","_blank")');
		slate.style.cursor = 'pointer';
		slate.width = currentCVPPage[instanceCount].width;
		slate.height = currentCVPPage[instanceCount].height;
		try {
			var containerElement = document.getElementById(currentCVPPage[instanceCount].videoContainerId);
			var parentElement = containerElement.parentNode;
			parentElement.replaceChild(slate,containerElement);
		} catch(e) {}
	},
	
	/******************* START - Player instances set in config.xml (/.element/apps/cvp/4.0/cfg/xml/config.xml) ************************/
	players: {
		main: {
			id: 'cvpMain',
			width: '640',
			height: '360',
			context: 'main' /* context name defined in container.xml (/.element/apps/cvp/4.0/cfg/xml/container.xml) */
		},
		
		cheechako: {
			id: 'cvpCheechako',
			width: '640',
			height: '360',
			context: 'cheechako'
		},
		
		inline: {
			id: 'cvpInline',
			width: '288',
			height: '162',
			context: 'inline'
		},
		
		embed: {
			id: 'cvpEmbed',
			width: '400',
			height: '225',
			context: 'embed'
		},
		
		facebookEmbed: {
			id: 'cvpFacebookEmbed',
			width: '400',
			height: '225',
			context: 'facebook'
		}
	}
	/******************* END - Player instances set in config.xml (/.element/apps/cvp/4.0/cfg/xml/config.xml) ************************/
};
/* END - tourCVP object */


/******************************* START - Supplemental functions for CVP pages *************************************/

//setup a playlist to play
function cvp_playerReady() {
	var len = playlist.length;
	var theVideoId = '';
	if(playlist[0].id){
		theVideoId = 'id';
	}
	else{
		theVideoId = 'url';
	}
	var currId = cvp_prepareVideoId(playlist[0][theVideoId]);	//vId of the first video to play
	var vId;
	
	window[currentCVPPage[0].playerInstanceName].play(currId);	//play first video
	
	for(var i=0; i<=len-1; i++) {
		if(playlist[i].id){
			theVideoId = 'id';
		}
		else{
			theVideoId = 'url';
		}
		vId = cvp_prepareVideoId(playlist[i][theVideoId]);
		
		if(vId.indexOf(currId) == -1) {	//we don't want to queue the currently playing video
			window[currentCVPPage[0].playerInstanceName].queue(vId);
		}
	}
}

function cvp_prepareVideoId(vId) {
	if(/\/video.json$/.test(vId)) {	//remove /video.json from end
		vId = vId.replace(/\/video.json$/, "");
	}
	
	if(/\/$/.test(vId)) {	//remove trailing slash
		vId = vId.replace(/\/$/, "");
	}
	
	if(/&adTest=1$/.test(vId)) {	//remove &adTest=1 from end
		vId = vId.replace(/&adTest=1$/, "");
	}
	
	return vId;
}

//update video source or related link
function cvp_getRelatedUrl(vId) {
	var rDiv = document.getElementById('tourCVPRelatedLink');
	rDiv.innerHTML = '';	//clear div contents, for replays
	
	var jsonText = tourCVPMain.getContentEntry(vId);
	var videoObj = jsonText.evalJSON();	//create a video object
	
	if(videoObj && typeof videoObj.urls == 'object' && videoObj.urls.relateds != '') {
		var relatedP = document.createElement('p');
		rDiv.appendChild(relatedP);
		relatedP.id = 'tourRelatedUrl';
		
		var relatedA = document.createElement('a');
		relatedP.appendChild(relatedA);
		
		if(videoObj.urls.relateds.length == null) {	//only one related item
			if (videoObj.urls.relateds.story.headline == 'PGATOUR.com') {
				return;
			}
			relatedA.setAttribute('href', videoObj.urls.relateds.story.url.html);
			relatedA.appendChild(document.createTextNode(videoObj.urls.relateds.story.headline));
		} else {	//2 or more related items
			if ( videoObj.urls.relateds[0].story.headline != 'PGATOUR.com' ) {
			relatedA.setAttribute('href', videoObj.urls.relateds[0].story.url.html);	//we will assume that the first related url is always what we are looking for
			relatedA.appendChild(document.createTextNode(videoObj.urls.relateds[0].story.headline));
		}
	}
	} else {
		//something happened
	}
}

//update the video source link (ex: Courtesy of blah.com)
function cvp_updateSourceLink(videoObj, vidDiv) {
	var sourceP = document.createElement('p');
	vidDiv.appendChild(sourceP);
	sourceP.id = 'video_source';

	var sourceA = document.createElement('a');
	sourceP.appendChild(sourceA);

	if(videoObj.urls.relateds.length == null) {	//only one related item
		if (videoObj.urls.relateds.story.headline == 'PGATOUR.com') {
			return;
		}
		sourceA.setAttribute('href', videoObj.urls.relateds.story.url.html);
		sourceA.appendChild(document.createTextNode(videoObj.urls.relateds.story.headline));
//}
	} else {	//2 or more related items
		if ( videoObj.urls.relateds[0].story.headline.indexOf('PGATOUR.com') == -1) {
		sourceA.setAttribute('href', videoObj.urls.relateds[0].story.url.html);	//we will assume that the first related url is always what we are looking for.
		sourceA.appendChild(document.createTextNode(videoObj.urls.relateds[0].story.headline));
	}
	}
}

function cvp_updateVideoHeadlineDescription(vId) {
	var vidDiv = document.getElementById('tourVidDetailBlurb');
	//var vidDescDiv = document.getElementById('tourCVPDescription');
	vidDiv.innerHTML = '';	//clear div contents, for replays

	//var videoUrl = document.getElementById('tourVidDetailURL');
	//videoUrl.innerHTML = '';

	var headline = document.createElement('h3');
	vidDiv.appendChild(headline);
	var descript = document.createElement('div');
	vidDiv.appendChild(descript);

	headline.id = "video_headline";
	descript.id = "video_description";
	
	//document.getElementById('video_description').style.height = '50px';

	//var vidUrlInput = document.createElement('input');
	//videoUrl.appendChild(vidUrlInput);

	//vidUrlInput.setAttribute('id', 'staticlink');
	//vidUrlInput.setAttribute('name', 'staticlink');

	var jsonText = tourCVPMain.getContentEntry(vId);
	var videoObj = jsonText.evalJSON();	//create a video object

	if(!videoObj) {	//if the video object is null for some reason, update headline and desc with blank strings
		headline.appendChild(document.createTextNode(''));
		descript.appendChild(document.createTextNode(''));
		
		//vidUrlInput.setAttribute('style', 'display:none');
	} else {
		headline.appendChild(document.createTextNode(videoObj.headline));
		descript.appendChild(document.createTextNode(videoObj.description));

		var objVId = videoObj.id;
		if(/\/video\/video/.test(objVId)) {	//remove /video.json from end
			objVId = objVId.replace(/\/video\/video/, "/video");
		}

		/*var vidPBaseUrl = "http://www.pgatour.com/video/";
		var endIndex = location.href.indexOf('?');
		if (endIndex == -1) { endIndex = location.href.lastIndexOf('/') + 1; }
		if (endIndex > 0) { vidPBaseUrl = location.href.substring(0,endIndex) + '?'; }

		vidUrlInput.setAttribute('style', 'display:block');
		vidUrlInput.setAttribute('onclick', 'this.focus();this.select();');
		vidUrlInput.setAttribute('value', vidPBaseUrl+objVId);*/

		if(videoObj.urls.relateds != '') {
			cvp_updateSourceLink(videoObj, vidDiv);
		}
	}
}

/* Start - Player Profile Page load video headline function */
function cvp_loadVideoHeadlineDescription(video) {
	var vidDiv = document.getElementById('tourVidDetailBlurb');
	vidDiv.innerHTML = '';	//clear div contents, for replays

	var headline = document.createElement('h3');
	vidDiv.appendChild(headline);
	var descript = document.createElement('div');
	vidDiv.appendChild(descript);

	headline.id = "video_headline";
	descript.id = "video_description";

	if(!video) {	//if the video object is null for some reason, update headline and desc with blank strings
		headline.appendChild(document.createTextNode(''));
		descript.appendChild(document.createTextNode(''));
		
		//vidUrlInput.setAttribute('style', 'display:none');
	} else {
		headline.appendChild(document.createTextNode(video.title));
		descript.appendChild(document.createTextNode(video.metadata.media.excerpt));
	}
}
/* End - Player Profile Page load video headline function */


//play a video with vId
function cvp_playVideo(vId, weekNum, vidIn) {
window[currentCVPPage[0].playerInstanceName].play(cvp_prepareVideoId(vId));
	try {
		s = weeks[weekNum].playlist[vidIn];
		if(s.shortDescription){
			$('tourRTCVideoTitle').innerHTML = s.shortDescription;
		}
		else{
			$('tourRTCVideoTitle').innerHTML = s.title;
		}
		$('tourRTCVideoDescription').innerHTML = s.description;
	} catch(e) {}
}

//enqueue videos from a playlist
function cvp_enqueueVideos(playlist, currId) {
	var len = playlist.length;
	var queueId;

	for(var i=0; i<=len-1; i++) {
		queueId = cvp_prepareVideoId(playlist[i].url);

		if(queueId.indexOf(currId) == -1) {	//we don't want to queue the currently playing video
			window[currentCVPPage[0].playerInstanceName].queue(queueId);
		}
	}
}

/* START - WGC video functions */
function cvp_initWGCPage() {
	var q = '';

	// Process what is being called
	var regex = new RegExp( "[?](.*)$" );
	var results = regex.exec( window.location.href );

	if (results && (!results.join('').match('dmtdebug|cvpoption'))){
		if (results.length == 2) q = results[1];
	}

	if(q=='') {
		loadVideo(playlist);
		return;
	} else if (q.match(/[a-z]+\/[0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/)) {	// q is a video
		if (!q.match(/^\/video\/video/) && !q.match(/^\/video\/audio/)) {
			q = '/video'+q;
		}
		loadVideo(q);
		return;
	}
}
/* END - WGC video functions */

// Video Play function
function loadVideo(video, override) {

	if(typeof video == 'string') {	//if video is a string, it is a single video
		cvp_playVideo(video);
	} else {	//else it's a playlist of videos size 1 to n
		var len = video.length;
		if(len == 0) {	//no playlist, just return
			return;
		}

		var currId = video[0].url;

		cvp_playVideo(currId);
		if(len > 1) {
			cvp_enqueueVideos(video, currId);
		}
	}
}

/* START - Homepage video functions */
function hideVideo() {
	// PGATOUR homepage and Euphony homepage T1's unfortunately use the same function name so an if...else statement needs to be setup to handle both
	// If on a euphony homepage
	if(window.location.pathname.match('^/tournaments/(r027|r028|r060|r505|r011|presidentscup)/(index.html)?')){
		if (tourT1PlayerReady == true) {
			window[currentCVPPage[0].playerInstanceName].play('/video/video/global/blackscreen.flv');
			setTimeout(function() { window[currentCVPPage[0].playerInstanceName].pause(); },'1000');
		}
		showHideSlides('show');
		// If the Slide show was not paused before video played, unpause it;
		if (!preVideoSlideShowState) { unpauseSlide(); }
	}
	// If on PGATOUR homepage
	else{
		if (tourT1PlayerReady == true) {
			window[currentCVPPage[0].playerInstanceName].pause();
		}
		$('tourHPT1VideoContainer').addClassName('videoHide');
		$('tourT1ViewPort').removeClassName('hide');
	}
}

function playVideo(vURL) {
	// PGATOUR homepage and Euphony homepage T1's unfortunately use the same function name so an if...else statement needs to be setup to handle both
	// If on a euphony homepage
	if(window.location.pathname.match('^/tournaments/(r027|r028|r060|r505|r011|presidentscup)/(index.html)?')){
		try { // When the slide count = 1, error occurs
			showHideSlides('hide');
			if (tourT1PlayerReady == false){
				currentCVPPage[0].flashVars.contentId=vURL;
				window[currentCVPPage[0].playerInstanceName] = new CVP(currentCVPPage[0]);
				window[currentCVPPage[0].playerInstanceName].embedSWF(currentCVPPage[0].videoContainerId);
			} else {
				window[currentCVPPage[0].playerInstanceName].play(vURL);
			}
			// See if the slides were paused before this call
			preVideoSlideShowState = t1IsPaused;
			// Pause Slide
			pauseSlide();
		}
		catch(e) {}
	}
	// If on PGATOUR homepage
	else{
		if(tourT1PlayerReady == false && (CVP.swfobject.hasFlashPlayerVersion(tourCVP.minimumRequiredFlashVersion) || (navigator.userAgent.indexOf('iPad') != -1))){
			currentCVPPage[0].flashVars.contentId=vURL;
			window[currentCVPPage[0].playerInstanceName] = new CVP(currentCVPPage[0]);
			window[currentCVPPage[0].playerInstanceName].embedSWF(currentCVPPage[0].videoContainerId);
		}
		else if((!CVP.swfobject.hasFlashPlayerVersion(tourCVP.minimumRequiredFlashVersion)) && (navigator.userAgent.indexOf('iPad') == -1)){
			$(currentCVPPage[0].videoContainerId).update('<img src="http://i.cdn.turner.com/pgatour/.element/apps/cvp/4.0/img/'+currentCVPPage[0].width+'x'+currentCVPPage[0].height+'_flash_slate.jpg" style="cursor:pointer" onclick="window.open(\'http://get.adobe.com/flashplayer/\',\'_blank\')" />');
		}
		else {
			window[currentCVPPage[0].playerInstanceName].play(vURL);
		}
		$('tourT1ViewPort').addClassName('hide');
		$('tourHPT1VideoContainer').removeClassName('videoHide');
	}
}
/* END - Homepage video functions */

/* START - Euphony video functions */
function cvp_initEuphonyPage() {
	var q = '';
	
	// Process what is being called
	var regex = new RegExp( "[?](.*)$" );
	var results = regex.exec( window.location.href );
	
	if (results && (!results.join('').match('dmtdebug|cvpoption'))){
		if (results.length == 2) q = results[1];
	}
	
	if(q=='') {
		loadVideo(playlist);
		return;
	} else if (q.match(/[a-z]+\/[0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/)) {	// q is a video
		if (!q.match(/^\/video\/video/) && !q.match(/^\/video\/audio/)) {
			q = '/video'+q;
		}
		loadVideo(q);
		return;
	}
}
/* END - Euphony video functions */

/* START - Leaderboard right rail video functions */
var isRefresh = false;
var rrPlaylist;
var plRefreshId;
var contentHeight = 0;
var oldHighlight = 'tourRRVideo0';

//populate div with video list
function populateVideoPlaylist(elId, pl) {
	var content = '';
	var len = pl.length;
	for (var i=0; i<len; i++) {
		var title = pl[i].title.replace(/amp;/g,'');
		
		if (pl[i].url != "") {
			content += '<div id="tourRRVideo'+i+'" class="tourRRVideoItem" url="'+pl[i].url+'" onclick="cvp_highlightVideoInList('+i+'); tourCVPRR.play(\''+pl[i].url+'\');" title="'+title+'"><span>'+title.truncate(41)+'</span></div>'+"\n";
		}
	}
	document.getElementById(elId).innerHTML = content;
	getContentHeight();
}

//change the class for the currently playing video
function cvp_highlightVideoInList(vIndex) {
	document.getElementById(oldHighlight).className = 'tourRRVideoItem';
	document.getElementById('tourRRVideo'+vIndex).className = 'tourRRVideoItem tourRRVideoSelected';
	
	oldHighlight = 'tourRRVideo'+vIndex;
	
	updateHeadlineAndDescription(vIndex);	//update the headline/description
}

//update the headline and description
function updateHeadlineAndDescription(vIndex) {
	document.getElementById('tourRRVideoHeadline').innerHTML = rrPlaylist[vIndex].title;
	document.getElementById('tourRRVideoDesc').innerHTML = rrPlaylist[vIndex].description;
}

//ajax call to get the latest playlist file
function fetchPlaylist() {
	var plFile = '/.element/ssi/auto/3.0/aps/sect/video/tournament/'+tId+'/leaderboard/assets_max_15.json';	//tId is a global set in the lb's index.html
	
	new Ajax.Request(plFile, {
			method:'get',
			onFailure: function(oXHR, oJson) {	//mainly to catch playlist json file 404s
				document.getElementById('tourRRVideoListContent').innerHTML = '<div id="tourRRVideoErrorMsg">Video playlist currently unavailable</div>';
				getTimeNow();	//output last updated time
				//if we wanted to hide the video player, we could use the below line
				//document.getElementById('tourRRVideoContainer').setStyle({display: 'none'});
			},
			onSuccess: function(transport) {
				rrPlaylist = transport.responseText.evalJSON(true);

				populateVideoPlaylist('tourRRVideoListContent', rrPlaylist);
				cvp_highlightVideoInList('0');	//highlight first video in list
				
				document.getElementById('tourRRVideoHeadline').innerHTML = rrPlaylist[0].title;
				document.getElementById('tourRRVideoDesc').innerHTML = rrPlaylist[0].description;
				
				getTimeNow();	//output last updated time
				
				if(!isRefresh) {	//only on initial page load
					tourCVPRR.play(rrPlaylist[0].url);
				}
			}
	});
}

//retrieve the client time and do some 12-hour logic
function getTimeNow() {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var date = now.getDate();
	var month = now.getMonth();
	var year = now.getFullYear();
	var ampm = 'am';
	var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
	
	if(hours > 11) {
		ampm = 'pm';
	}
	
	if(hours > 12) {
		hours = hours-12;
		
	} else if (hours == 0) {
		hours = 12;
	}
	
	if(minutes < 10) {
		minutes = '0'+minutes;
	}
	document.getElementById('tourRRVideoLastUpdate').innerHTML = 'Updated: '+monthNames[month]+' '+date+', '+year+'&nbsp;'+hours+':'+minutes+'&nbsp;'+ampm;
}

//remove the passed in element from the DOM
function removeEl(id) {
	var el = document.getElementById(id);
	el.parentNode.removeChild(el);
}

//things to do on playlist refresh
function refreshPlaylist() {
	isRefresh = true;
	removeEl('cvpRR');
	
	var container = document.getElementById('tourCVPPlaceholder');
	var newDiv = document.createElement('div');
	newDiv.id = 'cvpRRDiv';
	container.appendChild(newDiv);
	tourCVPRR.embedSWF('cvpRRDiv');
	
	fetchPlaylist();
}

//scroll up
function moveUp() {
	var speed = 3;
	var vListContainer = document.getElementById('tourRRVideoListContent');
	
	if (parseInt(vListContainer.style.top) <= 0) {
		vListContainer.style.top = parseInt(vListContainer.style.top)+speed+"px";
	}
	moveUpVar=setTimeout("moveUp()", 20);
}

//scroll down
function moveDown() {
	var speed = 3;
	var vListContainer = document.getElementById('tourRRVideoListContent');
	
	if(parseInt(vListContainer.style.top) >= (contentHeight*(-1)+210)) {
		vListContainer.style.top = parseInt(vListContainer.style.top)-speed+"px";
	}
	moveDownVar=setTimeout("moveDown()", 20);
}

//get the height of the playlist div
function getContentHeight() {
	contentHeight = document.getElementById('tourRRVideoListContent').offsetHeight;
}
/* END - Leaderboard right rail video functions */

/* START - WGC homepage right rail video functions */
//make the watch more link point to the video page of the tournament that the currently playing video is from.  used on the WGC hp
function swapWatchMoreLink(vId) {
	var len = playlist.length;
	
	for(var i=0; i<len; i++) {
		if(playlist[i].url.indexOf(vId) != -1) {
			$('tourWGCWatchMore').href = '/tournaments/'+playlist[i].tID+'/video/';	//drop in tournament id of currently playing video
			return;
		}
	}
	
	//if for some reason there is no match, just use r470 as the watch more link so it's not broken
	$('tourWGCWatchMore').href = '/tournaments/r470/video/';
}
/* END - WGC homepage right rail video functions */

/******************************* END - Supplemental functions for CVP pages *************************************/

// Initialize CVP on the page if you're not on a player profile page. Player profile pages make the tourCVP.initialize() call themselves, if necessary.
Event.observe(window, 'load', function(){ if(!window.location.pathname.match('^/golfers/[0-9]{6}/|^/players/[0-9]{2}/[0-9]{2}/[0-9]{2}/')) { tourCVP.initialize(); } });
