/** TOUR fantasy page video player **/
cvpFlashVars.player = 'inline'+cvpPlayerTest;

//define player config
tourCVPFantasy = new CVP({
	id: 'cvpFantasy',
	width: '288',
	height: '162',
	flashVars: cvpFlashVars,
	
	embed : {
		containerSwf : cvpContainerSwf
	},
	
	onPlayerReady: function() {
		this.setAdSection('pgatour.com_pgatour_fantasy'); // TODO: need to find out if SAS will want to create a new site section for this 
		cvp_playerReady();
		this.mute();	//default the player to muted
	},
	
	onContentPlay: function() {
		var jsonText = this.getContentEntry(this.getContentId());
		var vObj = jsonText.evalJSON();	//create a video object
		document.getElementById('cvpFantasyHeadline').innerHTML = vObj.headline;
		document.getElementById('cvpFantasyDescrip').innerHTML = vObj.description;
	},
	onAdStarted: function(token) {
	$('cvpFantasyHeadline').innerHTML = '';	//clear title and description during ad playback
	$('cvpFantasyDescrip').innerHTML = '';
	isAdPlaying = true;
	},

	onAdFinished: function(token) {
	isAdPlaying = false;
	},

	onContentTrackingAdCountdown: function(secs) {
	var secondWord = (secs == "1")?"second":"seconds";

	$('cvpFantasyHeadline').innerHTML = 'Next video will start in  ' + secs + ' ' + secondWord + '';
}
});

//setup a playlist to play
function cvp_playerReady() {
	var len = playlist.length;
	var currId = cvp_prepareVideoId(playlist[0].url);	//vId of the first video to play
	var vId;
	
	tourCVPFantasy.play(currId);	//play first video
	
	for(var i=0; i<=len-1; i++) {
		vId = cvp_prepareVideoId(playlist[i].url);
		
		if(vId.indexOf(currId) == -1) {	//we don't want to queue the currently playing video
			tourCVPFantasy.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(/\/$/, "");
	}
	return vId;
}

Event.observe(window, 'load', tourCVPFantasy.embedSWF('tourCVP'));