var max_points = 4;
var question_id = 0;
var earned_points = 0;
var named_booze = '';
total_questions = 17;

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

function init() {

  if ($('score')) {
    final_score = Math.floor($('score').value / (total_questions * 4) * 100);
    new Ajax.Updater('clues','/bb/quizzes/booze.php?score=' + final_score);  
    $('booze_list').innerHTML = '';
    $('points').innerHTML = '';
    $('footer').style.display = 'block';  
  } else {
    new Ajax.Updater('clues','/bb/quizzes/booze.php?question_id=0&clue_id=0');
    new Ajax.Updater('booze_list','/bb/quizzes/booze.php?show_booze_list=1');
  } 

}


function next_clue(question_id,clue_id) {
  max_points--;
  $('points').innerHTML = max_points + ' points left';
  new Ajax.Updater('clues','/bb/quizzes/booze.php?question_id=' + question_id + '&clue_id=' + clue_id);
  
  if (max_points <= 0) {
    new Ajax.Updater('booze_list','/bb/quizzes/booze.php?question_id=' + question_id + '&next_dialogue=0');
    max_points = 4;
    question_id++;
  }
  
}

function answer(answerElement,answer_id) {
  if (question_id != answer_id) { 
    
    max_points--;
    $('points').innerHTML = max_points + ' points left';
    
    answerElement.style.textDecoration = 'line-through';
    answerElement.innerHTML = answerElement.innerHTML + ' WRONG';
    answerElement.onclick = null;
    
    if (max_points <= 0) {
      new Ajax.Updater('clues','/bb/quizzes/booze.php?question_id=' + question_id + '&clue_id=10');
      new Ajax.Updater('booze_list','/bb/quizzes/booze.php?question_id=' + question_id + '&next_dialogue=0');
      max_points = 4;
      question_id++;
    }
    
  } else {
    $('booze_list').hide();
    earned_points += max_points;
    named_booze += question_id + ',';
    
    percentage = Math.floor(earned_points / (total_questions * 4) * 100);
    base_height = 207;
    new_height = base_height - Math.floor(base_height * earned_points / (total_questions * 5));
    new_height = new_height < 0 ? 0 : new_height; 
    $('drunk_empty').style.height = new_height + 'px';  
    
    new Ajax.Updater('booze_list','/bb/quizzes/booze.php?question_id=' + question_id + '&next_dialogue=1');
    new Ajax.Updater('clues','/bb/quizzes/booze.php?question_id=' + question_id + '&clue_id=10');    
    
    $('booze_list').show();
    
    question_id++;
  }
}

function next_question() {
  
  if (question_id >= total_questions) {
  
    dest_url = escape('www.oneplusyou.com/bb/booze?score=' + earned_points);
    window.location = "http://www.oneplusyou.com/q/v/m2_interstitial?dest_url=" + dest_url + '&view_key=booze';
    
//    final_score = Math.floor(earned_points / (total_questions * 4) * 100);
//    new Ajax.Updater('clues','/bb/quizzes/booze.php?score=' + final_score);  
//    $('booze_list').innerHTML = '';
//    $('points').innerHTML = '';  
//    $('footer').style.display = 'block';
    
  } else {  
    max_points = 4;
    $('points').innerHTML = max_points + ' points left';
    new Ajax.Updater('clues','/bb/quizzes/booze.php?question_id=' + question_id + '&clue_id=0');  
    new Ajax.Updater('booze_list','/bb/quizzes/booze.php?show_booze_list=1&named_booze=' + named_booze);
    $('booze_list').show();
  }
}