function updateHTML(elmId, value) {
  document.getElementById(elmId).innerHTML = value;
}

function onPlayerError(errorCode) {
  alert("An error occured of type:" + errorCode);
}

function onPlayerStateChange(newState) {
  updateHTML("playerState", newState);
}

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("ytPlayer");
  // This causes the updatePlayerInfo function to be called every 250ms to
  // get fresh data from the player
  setInterval(updatePlayerInfo, 250);
  updatePlayerInfo();
  ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
  ytplayer.addEventListener("onError", "onPlayerError");
}

function loadPlayer() {
  // The video to load
  var videoID = $('#videoDiv').attr('videoID');
  // Lets Flash from another domain call JavaScript
  var params = { allowScriptAccess: "always" };
  params.allowfullscreen = "true";
  params.wmode = "transparent";
  // The element id of the Flash embed
  var atts = { id: "ytPlayer" };
  // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
  swfobject.embedSWF("http://www.youtube.com/v/" + videoID + 
                     "?version=3&enablejsapi=1&playerapiid=player1", 
                     "videoDiv", "560", "340", "9", null, null, params, atts);
}
$(document).ready(function() {
  loadPlayer();  
})
