$(function()
{
	var top=550;
	var left = 260;
	var turn = 1;

	for (var i = 1; i <=6; i++)
	{

		left += 60 ;
		$('main').append('<div style="left:'+left+'px;top:'+top+'px;" class="textbox dragg " data-dropped="0" data-value="'+i+'">'+i+'</div>');

	}

	$(".dragg").draggable({ revert: true });

	$('.target').droppable(
			{
			addClasses: false,
			drop: function(event,ui)
				{

				if (ui.draggable.data('value') === $(this).data('value') && $(this).data('value') === turn)
					{

						top = $(this).position().top;
						left = $(this).position().left;
						ui.draggable.draggable({revert:false,disabled:true});
						ui.draggable.animate({left:left, top:top},{duration: 500, easing: 'easeOutBounce'});
						turn++;
						if (turn > 1 && turn < 7)
						{
							setTimeout(function()
							{

								$('#jplayer').jPlayer('setMedia', {mp3: './media/495-'+turn+'.mp3'}).jPlayer('play');

							}, 100);
						}
						if (turn === 7) {
							$('#jplayer_well').jPlayer('play');
						}
					} else {
						$('.wrong').fadeIn();
						setTimeout(function () {
						$('.wrong').fadeOut();
						}, 1500);
							}
				}
			});

});