document.write('<script src="http://swfobject.googlecode.com/svn/tags/rc3/swfobject/src/swfobject.js" type="text/javascript"></script>');

// allowScriptAccess must be set to allow the Javascript from one domain to access the swf on the youtube domain
var params = { allowScriptAccess: "always", bgcolor: "#ffffff", wmode: "transparent" };

if ( typeof YTcntr == "undefined" ) {
	var YTcntr=1;
}

function loadNewVideo(id) {
//alert(id);
//	if (window['ytplayer'+id]) {
		YTvideo_id = document.getElementById('YTvideo_id'+id).value;
		window['ytplayer'+id].loadVideoById(id, 0);
//	}
}


function play (id) {
	var YTvideo_id = null;
	if (window['ytplayer'+id]) {
		YTvideo_id = document.getElementById('YTvideo_id'+id).value;
		window['ytplayer'+id].loadVideoById(YTvideo_id,0);
		window['ytplayer'+id].playVideo();
	}
}

function stop (id) {
	if (window['ytplayer'+id]) {
		window['ytplayer'+id].stopVideo();
	}
}

function onYouTubePlayerReady(playerId) {
	window['ytplayer'+YTcntr] = document.getElementById("myytplayer"+YTcntr);
	window['ytplayer'+YTcntr].addEventListener("onStateChange", "onytplayerStateChange");
}

function drawYoutube(YTid, b, h) {
	YTcntr++;
	if ( typeof b == "undefined" ) {
		b = 150;
	}
	if ( typeof h == "undefined" ) {
		h = 120;
	}

	// this sets the id of the object or embed tag to 'myytplayer'. You then use this id to access the swf and make calls to the player's API
	var atts = { id: "myytplayer"+YTcntr };
	swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer"+YTcntr, "YTapiplayer_"+YTcntr, b, h, "8", null, null, params, atts);

	document.write('<link rel="stylesheet" href="css/yt_chromeless.css" type="text/css" />');

	document.write('<div style="height:' + h + 'px" id="YTcontainer">');
	document.write('<div id="YTapiplayer_'+YTcntr+'">&nbsp;</div>');
	document.write('	<div id="YTcontrols">');
	document.write('		<span id="YTctrl_start" onclick="play('+YTcntr+');"></span>');
	document.write('		<span id="YTctrl_stop" onclick="stop('+YTcntr+');"></span>');
	document.write('	</div>');
	document.write('	<input id="YTvideo_id'+YTcntr+'" type="hidden" value="' + YTid + '" />');
	document.write('</div>');
	// document.write("<script language=\"JavaScript\">"+loadNewVideo(YTid)+"</script>");
}
