function onTemplateLoaded(experienceID) {
    bcExp = brightcove.getExperience(experienceID);
    modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
	modVP.addEventListener(BCMediaEvent.BEGIN, onMediaStart);
	modVP.addEventListener(BCMediaEvent.CHANGE, onMediaChange);
}

function onMediaChange(evt){
	currentVideo = modVP.getCurrentVideo();
	myVideoID = currentVideo.id;
	loadEpisodeRating();
	loadDescription();
}

function onMediaStart(evt){
	currentVideo = modVP.getCurrentVideo();
	myVideoID = currentVideo.id;
	$.ajax({
		type: "GET",
		url: "/webservice/view-episode.php",
		cache: false,
		data: "id=" + myVideoID	
	});	
}

function loadEpisodeRating(){
	if(myVideoID != null){
		hideRatings();
		$.ajax({
			type: "GET",
			url: "/webservice/episode-rating.php",
			cache: false,
			data: "id=" + myVideoID,
			success: function(msg){
				$("div#ratingImageWrapper").html(msg);
				setTimeout("showRatings()", 1000);
			}
		});
		

		
	}
}

function loadDescription(){
	if(myVideoID != null){
		$.ajax({
			type: "GET",
			url: "/webservice/episode-description.php",
			cache: false,
			data: "id=" + myVideoID,
			success: function(msg){
				$("div#synopsis").html(msg);
			}
		});	
	}
}

function hideRatings(){
	$("div#ratingImageWrapper").fadeOut();
}

function showRatings(){
	$("div#ratingImageWrapper").fadeIn();
}

function voteComplete(){
	$("div#ratingStatus").html('Rating submitted!');
	setTimeout("loadEpisodeRating()", 1000);
}

