
$(function()
	{





	var counter = 0;


	/**
	 * Draggable
	 */
	$('.elements > *').each(function()
		{
		var $this = $(this);

		$this.draggable(
			{
			containment: $('main'),
			cursor: 'move',
			scope: $this.data('kind'),
			opacity: .7
                        });
		});

	/**
	 * Droppable
	 */

	$('.box').each(function()
		{
		var $this = $(this);

		$this.droppable(
			{
			accept: $('.elements > *'),
    			addClasses: false,
			scope: $this.data('kind'),
                        out: function( event, ui )
                                {

                                    if (ui.draggable.data('dropped') === 1)
                                            {
                                            ui.draggable.data('dropped',0);
					    counter--;

                                            }
                                },

			drop: function(event,ui)
				{

                                     if (ui.draggable.data('dropped') === 0)
                                            {
                                            ui.draggable.data('dropped',1);
					    counter++;

					    }


				}

			});
		});



	/**
	 * jPlayer
	 */
	for(var i=1;i<=3;++i)
		{
		$('#jplayer_melody'+i).jPlayer(
			{
			ready: function()
				{
				$(this).jPlayer('setMedia', {mp3: './media/melody_'+i+'.mp3'});
				},

			play: function()
				{
				$(this).jPlayer('pauseOthers');
				},

			swfPath: '../../styles/flash',
			supplied: 'mp3',
			cssSelectorAncestor: '#jp_container_melody'+i
			});
		}
	$('#jplayer_melody1').on($.jPlayer.event.ready,function()
		{
		$('#jplayer_melody1').jPlayer('setMedia', {mp3: './media/melody_1.mp3'});
		});
	

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

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


		$('.footer_game .check').click(function(e)
		{
		e.preventDefault();

		if(counter === 3)
			{
			$('#jplayer_well').jPlayer('play');
			}
		else
			{
			$('#jplayer_wrong').jPlayer('play');
			}
		});

	});
