//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" };

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


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

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

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


function loadFirstVideo(YTid){
	loadNewVideo(YTid, "0");
}


function startYT() {
	noneDiv('YTFirstFrame');
	play();
//		window['ytplayer'].playVideo();
}

function drawYoutube(YTid, b, h) {
	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" };
	swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", "YTapiplayer", b, h, "8", null, null, params, atts);
	document.write('<div id="YTcontainer" style="width:'+b+'px; height:'+h+'px">');
	document.write('	<div id="YTapiplayer" style="position:absolute; left:0px; top:0px;">&nbsp;</div>');
	document.write('	<div id="YTcontrols" style="position:absolute; left:5px; top:' + (h-25) + 'px; width:50px; height:20px ;">');
	document.write('		<span id="YTctrl_start" onclick="play();"></span>');
	document.write('		<span id="YTctrl_stop" onclick="stop();"></span>');
	document.write('	</div>');
	document.write('	<div id="YTFirstFrame" style="position:absolute; left:0px; top:0px; background:#000 url(http://img.youtube.com/vi/' + YTid + '/0.jpg) center 50% no-repeat">');
	document.write('		<div style="background:url(images/yt_start_groot.gif) center 50% no-repeat;">');
	document.write('			<a href="javascript:play();noneDiv(\'YTFirstFrame\');"><img src="images/1x1trans.gif" style="width:'+b+'px; height:'+h+'px; " border="0" /></a>');
	document.write('		</div>');
	document.write('	</div>');
	document.write('</div>');

	document.write('	<input id="YTvideo_id" type="hidden" value="' + YTid + '" />');

}
