$(function ()
{
    var zindex = 10;
    var left;
    var top;
    
    $('#jplayer').on($.jPlayer.event.ready, function (){
        $('#jplayer').jPlayer('setMedia', {mp3: './media/file2.mp3'});
    });

    $(".dragg").draggable({
        start: function () {
            zindex++;
            $(this).css('z-index', zindex);
            left = $(this).css('left');
            top = $(this).css('top');
        }
    });

    var drop = function (event, ui) {
        if ($(this).data('value') === ui.draggable.data('value')) {
            ui.draggable.data('ok', 1);
            ui.draggable.css('display', "none");
            $(".cell[data-value='" + $(this).data('value') + "'] > span").css('display', 'block');
            check();
        }
        else {
            $('#jplayer_wrong').jPlayer('play');
            ui.draggable.animate({
                left: left,
                top: top
            },
            900
                    );
        }
    };
    
    $(".cell").droppable({
        accept: ".txt",
        drop: drop
    });
    
    function check() {
        var a = $("#t1").data('ok');
        var b = $("#t2").data('ok');
        var c = $("#t3").data('ok');
        var d = $("#t4").data('ok');
        var e = $("#t5").data('ok');
        var f = $("#t6").data('ok');
        var g = $("#t7").data('ok');
        var h = $("#t8").data('ok');
        var i = $("#t9").data('ok');
        var j = $("#t10").data('ok');
        if (a + b + c + d + e + f + g + h + i + j === 10)
        {
            $('#jplayer_well').jPlayer('play');
        }
    }
}
);