$(function ()
{

    var left=[0,0,0],
    zindex = 10,
    dropped =0;

    $(".dragg").draggable({
	start: function () {
	    zindex++;
	    $(this).css('z-index', zindex);
	},
	revertDuration: 900,
	revert: true
    });

    var drop = function (event, ui) {
	if ($(this).data('value') === ui.draggable.data('value')) {
	    $('#jplayer_well').jPlayer('play');
	    var position = $(this).position();
            	    ui.draggable.css('top', position.top+9);
            ui.draggable.css('left', position.left+left[$(this).data('value')-1]);
            left[$(this).data('value')-1] += ui.draggable.width()+20;
            dropped++;
	    ui.draggable.draggable({revert: false});
	    ui.draggable.draggable("option", "disabled", true);
            if (dropped === 10){
                $('.jajo').fadeIn(400);
            }
            
	} else {
	    $('#jplayer_wrong').jPlayer('play');
	}
    };


    $(".drop").droppable({
	accept: ".dragg",
	tolerance: "pointer",
	drop: drop
    });
});