
$(function()
	{
		var zindex = 10, counter = 2, j = 0;

		$('#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');
				},100);
			}
		});
		var drop = function (event, ui) {
			var x = ui.draggable.data('value');
			var y = $(this).data('value');
			
			if (x === y) {
				var top = $(this).position().top;
				var left = $(this).position().left;
				
				ui.draggable
					.draggable({revert: false})
					.draggable("option", "disabled", true);
				ui.draggable.animate({
					top:  top,
					left: left
				}, 900); 
				
				setTimeout(function()
					
						{
							if(counter !== 10) {$('#jplayer').jPlayer('setMedia', {mp3: './media/'+counter+'.mp3'}).jPlayer('play');j++;}
							else{}
						},100);
				
				counter++;
				
				if (j === 7) {
					$('#jplayer_well').delay(1000).jPlayer('play');	
				}
			} 
			else {
				$('.nope').fadeIn(700).delay(1200).fadeOut(700);
				$('#jplayer_wrong').jPlayer('play');
			}
		};
			
					
		$('.dragz').draggable({
			start: function () {
				zindex++;
				$(this).css('z-index', zindex);
			},
			revert: true,
			revertDuration: 800
		});
		$('.dropz').droppable({
			accept: ".dragz",
			tolerance: "touch",
			drop: drop
		});
		$('#jplayer_sound').jPlayer({
        ready: function () {
            $(this).jPlayer('setMedia', {mp3: './media/803-1.mp3'});
        },
        swfPath: '../../styles/flash',
        supplied: 'mp3',
        cssSelectorAncestor: '#jp_container_sound'
    });

	});
