$(function()
{
    var gameType = $('.cymbals').attr( 'data-type' );
    if(gameType == 1){ var current = 1; var next = 2;}
    else if (gameType == 2){ var current = 8; var next = 7;}
    
    $('#jplayer'+gameType).jPlayer( {
        ready: function() {
            $(this).jPlayer('setMedia', {mp3: './media/101_'+gameType+'.mp3'});
        },
        
        play: function() {
            $(this).jPlayer('pauseOthers');
        },

	swfPath: '../../styles/flash',
	supplied: 'mp3',
	cssSelectorAncestor: '#jp_container'
    });
    
    for(var i=1;i<=8;++i)
    {
        $('main').append('<div class="cymb element_'+i+'" data-value="'+i+'"></div>'); 
        $('main').append('<div id="jplayer_sound'+i+'" class="jp-jplayer"></div>');                           
    } 

    $('.cymb').click(function() {
        var id = $(this).attr( 'data-value' );
        
        if(gameType < 3) {
            if(id == current) {
                var audioElement = document.createElement('audio');
                audioElement.setAttribute('src', './media/cym'+id+'.mp3');
                audioElement.play();  
                if(gameType == 1) { 
                    if(current == 8) $("#jplayer_well").jPlayer("play");
                    current += 1;
                    next += 1;
                } else if (gameType == 2){ 
                    if(current == 1) $("#jplayer_well").jPlayer("play");
                    current -= 1;
                    next -= 1;
                }
            } else $("#jplayer_wrong").jPlayer("play");
        } else {            
            var audioElement = document.createElement('audio');
            audioElement.setAttribute('src', './media/cym'+id+'.mp3');
            audioElement.play();
        }
    });
});
