/* GR - 2010 - JL Biellmann */

var _yt = {
	// DIVs : ytanim -> ytapiplayer -> myytplayer
	videoNum : 0,
	params : { allowScriptAccess: 'always', allowFullScreen: true, autoplay: true, wmode: 'opaque' },
	atts : { id: 'myytplayer' },
	play : function (num) {
		_yt.videoNum = num;

		$('ytanim').update('');
		var div = E('div',{'id':'ytapiplayer'});
		$('ytanim').appendChild(div);
		
		// real size 640/390
		// old size : '425', '344
		if (num==1)
			swfobject.embedSWF('http://www.youtube.com/v/DM16mIvIrnM?enablejsapi=1&amp;playerapiid=ytplayer&amp;hl=fr&amp;fs=1&amp;rel=0&amp;color1=0xe1600f&amp;color2=0xfebd01&amp;amp;autoplay=1', 'ytapiplayer', '400', '300', '8', null, null, _yt.params, _yt.atts);
	},
	onStateChange : function (newState) {
		// unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5)
		//if (newState==0) {
			//if (_yt.videoNum==1)
				//setTimeout(function () {_yt.play(2);},500); // for midori...
			//else
				//_yt.videoNum = 1;
		//}
	},
	onError : function (err) {
		alert(err);
	},
	chgVideo : function (num) {
		if ($('myytplayer') && $('myytplayer').stopVideo)
			$('myytplayer').stopVideo();
		_yt.play(num);
	}
};

function onYouTubePlayerReady (playerId) {
	$('myytplayer').addEventListener('onStateChange', '_yt.onStateChange');
	$('myytplayer').addEventListener('onError', '_yt.onError');
}

Event.observe(window,'load',function () {_yt.play(1);});

