
$(function()
	{
	var drop = [0,0,0,0,0];



	$('.elements > *,.marks > *').each(function()
	{
	var $this = $(this);
	$this.attr('data-dropped',0);
	$this.draggable(
		{
		containment: $('main'),
		cursor: 'move',
		opacity: .7
		});
	});



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

		$this.droppable(
			{
			accept: $('.elements > *,.marks > *'),
			addClasses: false,
			out: function(event,ui)
				{
					   if (ui.draggable.attr('data-dropped') === "1")
                                            {
                                            ui.draggable.attr( 'data-dropped', "0");

							if (drop[$(event.target).data('index')] === ui.draggable.text()) drop[$(event.target).data('index')] = 0;

                                            }

				},
			drop: function(event,ui)
				{
					   if (ui.draggable.attr('data-dropped') === "0")
                                            {
                                            ui.draggable.attr( 'data-dropped', "1");

							drop[$(event.target).data('index')] = ui.draggable.text();



                                            }


				}
			});
		});





	/**
	 * Check
	 */
	$('.footer_game .check').click(function(e)
		{
		e.preventDefault();
		var ok = true;


		if (!(  (Number(drop[0]) + Number(drop[2]) === 9) && (drop[1]==="+")  && (drop[3]==="=") && (drop[4]==="9")  )) ok = false;

		

		if(ok)
			{
			$('#jplayer_well').jPlayer('play');
			}
		else
			{
			$('#jplayer_wrong').jPlayer('play');
			}
		});



	});
