// JavaScript Document
function updateHTML(elmId, value) {
  document.getElementById(elmId).innerHTML = value;
}

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer");
  setInterval(updateytplayerInfo, 250);
  updateytplayerInfo();
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
  ytplayer.addEventListener("onError", "onPlayerError");
}

function onPlayerError(errorCode) {
  alert("An error occured: " + errorCode);
}

// functions for the api calls
function loadNewVideo(id, startSeconds) {
  if (ytplayer) {
	ytplayer.loadVideoById(id, parseInt(startSeconds));
  }
}

function cueNewVideo(id, startSeconds) {
  if (ytplayer) {
	ytplayer.cueVideoById(id, startSeconds);
  }
}

function play() {
  if (ytplayer) {
	ytplayer.playVideo();
  }
}

function stop() {
  if (ytplayer) {
	ytplayer.stopVideo();
  }
}
