$(function()
{
	var count = 0;
	var play;
	var colors = [5,3,1,2,5,4];
	var order = [5,5,1,3,2,4];

	for(var i=1; i<=5; i++) {
		var top = 25 + (75*i);
		$('.elements').append('<div style="left: 200px; top: '+top+'px;" class="colors color_'+i+'" data-value="'+i+'"></div>');
	}

	for(var i=1; i<=6; i++) {
		$('.elements').append('<div class="letters element_'+i+'" data-value="'+colors[i-1]+'"></div>');
		$('.element_'+i).fadeTo(100, 0);
	}

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

	$(".letters").droppable({
        drop: function(event, ui) {
			if(ui.draggable.data("value") == $(this).data("value") && ui.draggable.data("value") == order[count]) {
				$(this).fadeTo(100, 1);
				count++;
				if (count > 1 && count < 6)
				{
					setTimeout(function()
					{

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

					}, 100);
				}

				if(count == 6) $('#jplayer_well').jPlayer('play');
			} else {
				$('#jplayer_wrong').jPlayer('play');
			}
		}
	});
});
