$(function()
{
	var top;
	var left;
	var zindex=100;
	var dataValue;
	var value = 8;
	var valueOk = 10;
	if ($('main').data('screen') === 2) {
	var value = 15;
	var valueOk = 20;
	$('#jplayer').on($.jPlayer.event.ready,function()
		{
			$('#jplayer').jPlayer('setMedia', {mp3: './media/file2.mp3'});

		});
	}
	$(".coin:not(.clone)").draggable(
			{
			contaiment: $('main'),
			helper: 'clone',
			revert: true
			});
	$('.target').droppable(
			{
			addClasses: false,
			drop: function(event,ui)
				{

				if (ui.draggable.data('dropped') === 0)
					{

						if (!ui.draggable.hasClass('clone'))
						{
							top = ui.helper.css('top');
							left = ui.helper.css('left');
							dataValue = ui.draggable.data('value');
							$('main').append('<div data-value="'+dataValue+'" data-dropped="1" style="z-index:'+zindex+';position: absolute; top: '+top+'; left: '+left+';" class="coin pln'+dataValue+' clone"></div>');
							zindex++;
							ui.helper.remove();
							$('.clone').draggable({contaiment: $('main'),
							start: function(){
							zindex++;
							$(this).css('z-index',zindex);
							}
							});
						}
						if (ui.draggable.hasClass('clone'))
							{
								ui.draggable.data('dropped',1);
							}

						value += ui.draggable.data('value');
					}
				},
				out: function(event, ui) {
					if (ui.draggable.data('dropped') === 1)
					{
						ui.draggable.data('dropped',0);
						value -= ui.draggable.data('value');
					}
				}
			});
$(".check").click(function() {
	if (value === valueOk) $('#jplayer_well').jPlayer('play');
			else $('#jplayer_wrong').jPlayer('play');
	});
});