
$(function()
	{

	/**
	 * jPlayer
	 */
	var sounds = ['tram','car','bicycle'];
	var counter = 0;

	$('#jplayer').on($.jPlayer.event.ended,function(event)
		{
		$('#jplayer_sound').jPlayer(
			{
			ready: function()
				{
				$(this).jPlayer('setMedia', {mp3: './media/tram.mp3'});
				},

			swfPath: '../../styles/flash',
			supplied: 'mp3',
			cssSelectorAncestor: '#jp_container_sound'
			});


			$('#jplayer_sound').on($.jPlayer.event.ready,function()
				{
					$('#jplayer_sound').jPlayer('play');
				});



		});


	/**
	 * Click
	 */
	$('.elements > *').click(function()
		{
		if($(this).data('element')-1 === counter)
			{

			$('#jplayer_sound').jPlayer('setMedia',{mp3: './media/'+sounds[counter]+'.mp3'}).jPlayer('play');
			$(this).animate({
				left:"-570px"
				}, 2000 );

			++counter;

			if(counter < 4)
				{
				setTimeout(function()
					{
					$('#jplayer_sound').jPlayer('setMedia', {mp3: './media/'+sounds[counter]+'.mp3'}).jPlayer('play');
					},1500);
				}
			else
				{
				setTimeout(function()
					{
					$('#jplayer_sound').jPlayer('setMedia', {mp3: './media/'+sounds[0]+'.mp3'});
					},1500);
				}
			}
		else
			{
			$('#jplayer_wrong').jPlayer('play');
			}
		});

	});

