function init()
{
	var params = { allowScriptAccess: "always", wmode: "transparent" };
	var atts = { id: "myytplayer" };
	swfobject.embedSWF("http://www.youtube.com/v/"+idAry[idPnt]+"&enablejsapi=1&playerapiid=ytplayer&loop=1&autoplay=0", "ytapiplayer", "346", "259", "8", null, null, params, atts);
}

function onYouTubePlayerReady(playerId)
{
	ytplayer = document.getElementById("myytplayer");
	ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(newState)
{
	if(newState == 0)
	{
		idPnt = (idPnt == idAry.length-1) ? 0 : (idPnt+1);
		swapMovie(idAry[idPnt]);
	}
}

function swapMovie(newMovieId)
{
	swfobject.removeSWF("myytplayer");
	
	var c = document.getElementById("ytapiplayer");
	if (!c)
	{
		var d = document.createElement("div");
		d.setAttribute("id", "ytapiplayer");
		document.getElementById("ytapiplayer_container").appendChild(d);
	}
	var atts = { data: "http://www.youtube.com/v/"+newMovieId+"&enablejsapi=1&playerapiid=ytplayer&loop=1&autoplay=0", id: "myytplayer", width:"346", height:"259" };
	var params = { allowScriptAccess: "always", wmode: "transparent" };
	swfobject.createSWF(atts, params, "ytapiplayer");
}

