var isAdPlaying = false;
var q = '';		//Setup the query string variable so that we can deep link into a video

getURLVars();

//When the page is loaded, create the instance of the video player
$(document).ready(function(){
	cvp_loadVideoPlayer('Microsite', '448', '252', 'videoPlayer', true);
});

//Update the title and headline div's
function cvp_updateMetadata(vId, headlinEl, descEl) {
	var jsonText = TURNERPLAYER.getVideoEntry(vId);
	var videoObj = eval( '(' + jsonText + ')' );
	document.getElementById(headlinEl).innerHTML = videoObj.headline;
	document.getElementById(descEl).innerHTML = videoObj.description;
}


/*** CVP JS Callback Functions ***/
//video player is loaded and ready to play
function onPlayerReady() {
	//Set subsection based on site you are on
	var url = window.location.pathname;
	var splitUrl = url.split("/");
	var site = splitUrl[1].toLowerCase();
	var adSection = 'pgatour.com_majors_'+site;
	
	//TFH - Remove If condition once all ad sections have been set up by ads team
	if(site.indexOf('grandslam') != -1){		
		TURNERPLAYER.setAdSection(adSection);
	}
	if (q != '') {
		microPlay(q);
	} else {
		var currId = playlist[0].url;
		currId = cvp_prepareVideoId(currId);

		cvp_enqueueVideos(playlist, currId);
		cvp_playVideo(playlist[0].url);
	}
}

//video has started playing
function onVideoPlayerPlay(videoId) {
	cvp_updateMetadata(videoId, 'videoHeadline', 'videoDescription');
}

//preroll has started
function onAdStarted(response)  {
    isAdPlaying = true;
}

//preroll has ended
function onAdFinished(response) {
	isAdPlaying = false;
}
