/** should be used wherever the "hp" player instance is needed **/
/** currently only used on the WGC hp **/
cvpFlashVars.player = 'hp'+cvpPlayerTest;

//define player config
tourCVPHp = new CVP({
	id: 'cvpHp',
	width: '288',
	height: '162',
	flashVars: cvpFlashVars,
	
	embed : {
		containerSwf : cvpContainerSwf
	},
	
	onPlayerReady: function() {
		this.setAdSection('wgc.com_homepage');	//if we ever use this for more than the WGC HP, we should add logic similar to cvp_main.js
		this.mute();	//default the player to muted
		cvp_playerReady();
	},
	
	onContentPlay: function() {
		swapWatchMoreLink(this.getContentId());
	}
});

//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;
	
	tourCVPHp.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
			tourCVPHp.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;
}

//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/';
}

Event.observe(window, 'load', tourCVPHp.embedSWF('tourCVP'));
