$(function ()
{


	var count = 1;
	var wrong = document.createElement('audio');
	var well = document.createElement('audio');
	wrong.setAttribute('src', '../../media/wrong.mp3');
	well.setAttribute('src', '../../media/well.mp3');


	$('#jplayer').on($.jPlayer.event.ended, function (event)
	{
		var src = _.last(event.jPlayer.status.src.split('/'));
		if (src === 'file.mp3')
		{
			setTimeout(function ()
			{
				$('#jplayer').jPlayer('setMedia', {mp3: './media/1.mp3'}).jPlayer('play');

			}, 1000);

			$('.click,main').click(function (event)
			{
				event.stopPropagation();
				if ($(this).data('value') === count)
				{
					$(this).addClass('select')
					count++;
					if (count < 7) {
						setTimeout(function ()
						{
							$('#jplayer').jPlayer('setMedia', {mp3: './media/' + count + '.mp3'}).jPlayer('play');
						}, 500);
					} else if (count === 7) {
						$('.well').fadeIn();
						well.play();
						$('.click,main').unbind('click');
					}

				}
				else {

					$('#jplayer').jPlayer('play');
					$('.wrong').fadeIn();
					setTimeout(function ()
					{
						$('.wrong').fadeOut();
					}, 1500);
					wrong.play();
				}
			});


		}
	});


});