$(function()
{
    var count = 0;
    $('#jplayer').on($.jPlayer.event.ended,function(event)
    {
	$('.sound').fadeIn();

	$('#jplayer_sound').jPlayer(
	{
            ready: function()
            {
		$(this).jPlayer('setMedia', {mp3: './media/105_wierszyk.mp3'});
            },

            swfPath: '../../styles/flash',
            supplied: 'mp3',
            cssSelectorAncestor: '#jp_container_sound'
	});
    });
    
    $(".draggable").draggable({ revert: true });
    for(var i=1;i<=7;++i)
    {
        $('main').append('<div class="targetbox" data-value="'+i+'"></div>');      
    } 

    $(".targetbox").droppable({
	drop: function(event, ui) {
            if(ui.draggable.attr( 'data-target' ) == $(this).attr("data-value")) {
                $(this).append('<div class="elements" id="box'+$(this).attr("data-value")+'"></div>');
                ui.draggable.clone(true).css('position', 'inherit').appendTo($('#box'+$(this).attr("data-value")));
		ui.draggable.remove();
                $(this).css('border-bottom', '0px');
                count++;
                if(count == 7)
                {
                    $("#jplayer_well").jPlayer("play");                     
                }
            }
	}
    });
});
