function onYouTubePlayerReady(playerId){
	var ytplayer = document.getElementById(playerId);
	var allCaps = document.getElementById(playerId + "_captionContainer").getElementsByTagName("div");
	var capIndex = new Array();
	for ( var i=allCaps.length-1; i>=0; --i ){
		capIndex[i] = new Array(3);
		capIndex[i][0] = allCaps[i].id.split("_tc")[1];
		if (allCaps[i + 1]) {
			capIndex[i][1] = allCaps[i + 1].id.split("_tc")[1];
		}
		else {capIndex[i][1] = 600000;}
		capIndex[i][2] = allCaps[i];
	}
	allCaps = null;
	setInterval(function() {playingDaemon(ytplayer, capIndex, playerId)}, 100);
}

function playingDaemon(ytplayer, capIndex, playerId){
	if (ytplayer.getPlayerState() == 1){
		var time = Math.round(ytplayer.getCurrentTime()*10)/10;
		//document.getElementById("timeCode").innerHTML = time;
		var caption = document.getElementById(playerId + "_tc" + time);
		for ( var i=capIndex.length-1; i>=0; --i ){
			if (capIndex[i][0] <= time && capIndex[i][1] > time) {
				capIndex[i][2].style.display = "block";
			}
			else {capIndex[i][2].style.display = "none";}
		}
	}
}

function loadYTCMovie(movie) {
	var params = { allowScriptAccess: "always", bgcolor: "#cccccc", wmode: "transparent" };
      var atts = { id: movie };
      swfobject.embedSWF("http://www.youtube.com/v/" + movie + "&amp;border=0&amp;enablejsapi=1&amp;playerapiid=" + movie, movie + "_ytapiplayer", "425", "344", "8", null, null, params, atts);
}