var score = 0;

var total_questions = 15;

var max_score = 97;

function begin() {
  if ($('score')) {
    new Ajax.Updater('question','/bb/quizzes/zombie.php?score='+$('score').value + '&random=' + random_int());
  } else {
    new Ajax.Updater('question','/bb/quizzes/zombie.php?question=0&random='+random_int());
  } 
}


function answer(question_id,answer) {
  
  $('question').innerHTML = 'Loading Next Question...';
  
  new Ajax.Request('/bb/quizzes/zombie.php',
    {
      method:'get',
      parameters: { question: question_id, answer: answer, random: random_int() },
      onSuccess: function(transport){
        
        var response = transport.responseText || "no response text";
        
        if (response.match(/POINTS:(\d+)/)) {
        
          score += parseFloat(RegExp.$1);
          
          percentage = (score / (max_score)) * 100;
          
          $('progress').style.width = Math.floor((percentage * 3.75)) + 'px';
          
          percentage = Math.floor(percentage);
          
        }
        
        question_id++;
        
        if (question_id >= total_questions) {
            dest_url = escape('www.oneplusyou.com/bb/zombie?score=' + percentage);
            window.location = "http://www.oneplusyou.com/q/v/m2_interstitial?dest_url=" + dest_url + '&view_key=zombie';
          //new Ajax.Updater('question','/bb/quizzes/zombie.php?score='+percentage+'&random='+random_int());
          //$('ads').style.display='block';
        } else {
          new Ajax.Updater('question','/bb/quizzes/zombie.php?question='+question_id+'&random='+random_int());
        }
        
      },
      onFailure: function(){ alert('Something went wrong...') }
    });
}


function random_int() {
 return Math.floor(Math.random()*100000);
}