var new_star_text = "Yes! You have earned a new star for your mission badge!";
var no_star_text = "Oops! No star for your badge. I'm sure you'll get the next one right!";

var latest_result = 0;

var nextStep = function() { };

function answer_selected(el)
{
    latest_result = parseInt($(el).val());
    score = score + latest_result;

    $('.bing_container').hide();
    $('.question_container form input[type=radio]').attr('disabled', true);
    $('#main_image').attr('src', image_1x);

    if (latest_result > 0)
    {
        $('.speech_bubble').text(question_right).css('top', 300).css('left', 216);
    }
    else
    {
        $('.speech_bubble').text(question_wrong).css('top', 300).css('left', 216);
    }

    $('.continue_container').css('display', 'inline');

    nextStep = function()
    {
        $('.question_container').hide();
        $('#main_image').attr('src', image_2);
        $('.speech_bubble').text(explanation_text).css('top', top2).css('left', left2);

        nextStep = function()
        {
            $('#main_image').attr('src', '../images/story_graphics/AW_' + score.toString() + '.jpg');

            if (latest_result > 0)
            {
                $('.speech_bubble').text(new_star_text).css('top', topStar).css('left', leftStar);
            }
            else
            {
                $('.speech_bubble').text(no_star_text).css('top', topStar).css('left', leftStar);
            }

            nextStep = function()
            {
                $('#main_image').attr('src', image_4);
                $('.speech_bubble').hide();

                nextStep = function()
                {
                    window.location.href = getNextPageLink(next_page, score);
                };
            };
        };
    };
}

function getScore()
{
    var url = window.location.href;
    var idx = url.indexOf('?score=');
    
    if (idx > 0)
    {
        return parseInt(url.substring(idx + 7));
    }

    return 0;
}

function getNextPageLink(pageName, score)
{
    return pageName + "?score=" + score.toString();
}

