var worth = 0;

// 11450 is the -real- max
var max_worth = 9000; 

var total_questions = 20;

Event.observe(window, 'load', init, false);

function init() {
  if ($('worth')) {
    new Ajax.Updater('question','/bb/quizzes/cadaver.php?worth='+$('worth').value);
  } else {
    new Ajax.Updater('question','/bb/quizzes/cadaver.php?question_id=0');
  }
}


function answer(question_id,answer_id) {
  
  $('question').innerHTML = 'Loading Next Question...';
  
  new Ajax.Request('/bb/quizzes/cadaver.php',
    {
      method:'get',
      parameters: { question_id: question_id, answer_id: answer_id },
      
      onSuccess: function(transport){
        
        var response = transport.responseText || "no response text";
        
        if (response.match(/WORTH:(\d+)/)) {
        
          worth += parseFloat(RegExp.$1);
         
          percentage = (worth / (max_worth)) * 100;
          
          $('progress').style.width = Math.floor(percentage * 5) + 'px';

        }
        
        question_id++;
        
        if (question_id >= total_questions) {
            dest_url = escape('www.oneplusyou.com/bb/cadaver?worth=' + worth);
            window.location = "http://www.oneplusyou.com/q/v/m2_interstitial?dest_url=" + dest_url + '&view_key=cadaver';
//          new Ajax.Updater('question','/bb/quizzes/cadaver.php?worth='+worth);
//          $('ads').style.display='block';
        } else {
          new Ajax.Updater('question','/bb/quizzes/cadaver.php?question_id='+question_id);
        }
        
      },
      onFailure: function(){ alert('Something went wrong...') }
    });
}


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