
$(function()
	{

	$('#jplayer').on($.jPlayer.event.ready,function()
		{
			$('#jplayer').jPlayer('setMedia', {mp3: './media/file2.mp3'});

		});



	$('.elements > *').each(function()
	{
	var $this = $(this);
	$this.draggable(
		{
		containment: $('main'),
		cursor: 'pointer',
		revert: true,
		opacity: .7
		});
	});


	var audioElement = document.createElement('audio');
	audioElement.setAttribute('autoplay', 'autoplay');


	$('.tree > *').each(function()
		{
		var $this = $(this);

		$this.droppable(
			{
			accept: $('.elements > *'),
			addClasses: false,
			drop: function(event,ui)
				{


				if (ui.draggable.data('target') === $(event.target).attr('class'))
				{

					$(event.target).html('<div class="'+ui.draggable.attr('class')+' hidden"></div>');
					$(event.target).children().fadeIn();
					ui.draggable.fadeOut(function()
					{
						$(this).remove();
					});
					audioElement.setAttribute('src', './media/'+$(event.target).data('play')+'.mp3');
					audioElement.play();
				}





				}
			});
		});


	});
