$(function () {
    var zindex = 10,
            dropped = 0,
            drop = function (event, ui) {
                if (ui.draggable.data('value') === $(this).data('value')) {
                    var top = $(this).position().top;
                    var left = $(this).position().left;
                    dropped++;
                    ui.draggable
                            .draggable({revert: false})
                            .draggable("option", "disabled", true);
                    $('#jplayer_well').jPlayer('play');
                    ui.draggable.animate({
                        top: top + 10,
                        left: left + 10
                    }, 900);
                } else {
                    $('#jplayer_wrong').jPlayer('play');
                }
            };

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

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

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

        $('#jplayer_sound_' + i).jPlayer({
            ready: function () {
                var id = $(this).attr('id');
                var no = id.replace('jplayer_sound_', '');
                $(this).jPlayer('setMedia', {mp3: './media/537-' + no + '.mp3'});
            },
            play: function ()
            {

                $(this).jPlayer('pauseOthers');

            },
            swfPath: '../../styles/flash',
            supplied: 'mp3',
            cssSelectorAncestor: '#jp_container_sound_' + i
        });

    }

});