$(function ()
{
var zindex = 10,
dropped = 0;



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

    var drop = function (event, ui) {
	if ($(this).data('value') !== ui.draggable.data('value')) {
	    $('#jplayer_wrong').jPlayer('play');
	} else {
	    ui.draggable
		    .draggable({revert: false})
		    .draggable({disabled: true});
	    var position = $(this).position();
	    var lewy = (ui.draggable.hasClass('left'))?-120:-80;
	    ui.draggable.addClass('small');
	    ui.draggable
		    .css('top', position.top + ($(this).height() - ui.draggable.height())-55)
		    .css('left', position.left + ($(this).width() - ui.draggable.width())+lewy);
	    dropped++;
	    if(dropped === 10){
		$('#jplayer_well').jPlayer('play');
			    setTimeout(function () {
		$(".dragg").removeClass('visible');
	    }, 1000);
	    setTimeout(function () {
		$(".rozwiazanie").addClass('visible');
	    }, 1200);
	    setTimeout(function () {
		$(".rozwiazanie").removeClass('visible');
	    }, 1400);
	    }
	}
    };


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

});