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

function onytplayerStateChange(newState) {
	if( newState == 0 )
	{
		jQuery(document).trigger('close.facebox');
	}
}

jQuery(document).ready(function() {
	$(document).bind('reveal.facebox', function () {
		$('#ytapiplayer').before('<a href="#" id="close_facebox" style="float: right; margin-right: 10px;">close</a>');
		$('#close_facebox').click(function (event) {
			event.preventDefault();
			jQuery(document).trigger('close.facebox');
		});
		var params = { allowScriptAccess: "always" };
		var atts = { id: "myytplayer" }; // , autoplay: 1

		swfobject.embedSWF("http://www.youtube.com/v/PwqN3ybOYDY&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer", 
			"ytapiplayer", "640", "390", "8", null, null, params, atts);
	});

	$('a#youtube').attr('href', '/scripts/youtube_video.htm');
	$('a[rel*=facebox]').facebox();
});

