$(function()
{
    if($('.method').attr( 'data-type' ) != 1) {
	$('#jplayer2').jPlayer(
	{
            ready: function()
            {
		$(this).jPlayer('setMedia', {mp3: './media/102_2.mp3'});
            },

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

		swfPath: '../../styles/flash',
		supplied: 'mp3',
		cssSelectorAncestor: '#jp_container'
	});
    }
    var rolls = [[1,1],[2,1],[3,2],[3,1],[4,1],[4,2],[5,1],[2,2],[1,3],[1,4],[1,5],[1,2],[2,3]];    
    var rolls_2 =[[6,1],[6,2],[6,3],[6,4],[6,5],[6,6],[5,1],[5,2],[5,3],[5,4],[5,5],[4,1],[4,2],[4,3],[4,4],
      [3,1],[3,2],[3,3],[2,1],[2,2],[1,1]];        
    var num1 = 0;
    var num2 = 0;
    var rightAnswer = 0;
    rollDice();    
    
    $('.rollbutton').click(function() {
        rollDice();        
    });
    
    $('.answer').click(function() {
        if($(this).text() == rightAnswer) $("#jplayer_well").jPlayer("play");
        else $("#jplayer_wrong").jPlayer("play");
    });
    
    function rollDice() {
        var roll = 0;
        if($('.method').attr( 'data-type' ) == 1) {
            var roll = (Math.floor((Math.random() * 13) + 1))-1;
            rightAnswer = rolls[roll][0] + rolls[roll][1];
            num1 = rolls[roll][0];
            num2 = rolls[roll][1];
        }
        else {
            var roll = (Math.floor((Math.random() * 21) + 1))-1;
            rightAnswer = rolls_2[roll][0] - rolls_2[roll][1];
            num1 = rolls_2[roll][0];
            num2 = rolls_2[roll][1];            
        }
        
        $('#greendice').remove();
        $('#yellowdice').remove();
        
        $('.elements').append('<div id="greendice" style="position: absolute; top: 100px; left: 78px;" class="green'+num1+'"></div>');
        $('.elements').append('<div id="yellowdice" style="position: absolute; top: 100px; left: 312px;" class="yellow'+num2+'"></div>');    
    }
});
