
$(function()
	{
	/**
	 * jPlayer
	 */

	var sounds = ['sailing','fishing-boat','motorboat'];
	var counter = 0;

	$('#jplayer').on($.jPlayer.event.ended,function(event)
		{
		$('#jplayer_sound').jPlayer(
			{
			ready: function()
				{
				$(this).jPlayer('setMedia', {mp3: './media/sailing.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');




			var animateTo= '-400px';
			if ($(this).hasClass('motorboat')) {
			animateTo = '1050px'
			} else animateTo= '-400px';


			$(this).animate({
			left: animateTo
			}, 2000 );


			++counter;

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


	});

