$(function ()
{
    var zindex = 10;

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

    var drop = function (event, ui) {
        if (ui.draggable.data('dropped') === 0) {
            ui.draggable.data('dropped', 1);
            $(this).data('value', ui.draggable.data('value'));
        }
    };

    var out = function (event, ui) {
        if (ui.draggable.data('dropped') === 1) {
            ui.draggable.data('dropped', 0);
            $(this).data('value', 0);
        }
    };

    $(".target_task").droppable({
        accept: ".task",
        tolerance: "pointer",
        drop: drop,
        out: out
    });

    $(".target_g").droppable({
        accept: ".g",
        tolerance: "pointer",
        drop: drop,
        out: out
    });
});