// Simulates radio buttons
//**********************************************************
function initializeSimulatedRadioGroups() {
  $('evaluator_questions').select('.simulated_radio_group').each(function(s) {
    var id = s.id.substring(18);
    new SimulatedRadioGroup(id);
  });
}

var SimulatedRadioGroup = Class.create({
  initialize: function(questionId) {
    // Instance variables
    this.id = 'eq_'+questionId;
    this.group = $('answer_options_'+this.id);
    this.finalAnswer = $(this.id);
    this.radios = [];

    this._answerQuestion = this.answerQuestion.bindAsEventListener(this);
    this.group.observe('click', this._answerQuestion);
    
    this.checkForSelectedAnswer();
  },

  answerQuestion: function(event) {
    var e = event.findElement();
    if (e.type=='button') {
      var answer = e.id.substring(e.id.lastIndexOf('_')+1);
      this.finalAnswer.value = answer;
      this.group.select('.simulated_radio').each(function(s) {
        s.removeClassName('selected_simulated_radio');
      });
      e.addClassName('selected_simulated_radio');
    }
  }, 
  
  checkForSelectedAnswer: function() {
    this.group.select('.simulated_radio').each(function(s) {
      var answer = s.id.substring(s.id.lastIndexOf('_')+1);
      if (answer==this.finalAnswer.value) s.addClassName('selected_simulated_radio');
    }, this);
  }

});
  

