Event.observe(window, 'load', setupFlashcards); 

function hideAllAnswers()
{
   var browserName=navigator.appName; 
   if (browserName != "Microsoft Internet Explorer")
   {
      var x = 1; 
      do
      {
         var controlName = 'answer' + x; 
         var control = $(controlName); 
         if (control)
         {
            control.style.display='none'; 
         }
         x++; 
      }
      while (control);    
   }
}

function trapQuestionClicks()
{
   var x = 1; 
   do
   {
      var controlName = 'question' + x; 
      var control = $(controlName); 
      if (control)
      {
         Event.observe(controlName, 'click', showAnswer); 
      }
      x++; 
   }
   while (control);    
}

function setupFlashcards()
{
   hideAllAnswers(); 
   trapQuestionClicks(); 
}

function showAnswer()
{
   var thisID = this.id; 
   var questionCaption = "question"; 
   
   //is this ID a question? 
   if (thisID.length > questionCaption.length)
   {
      if (thisID.substring(0, 8) == questionCaption)
      {
         var sequence = thisID.substring(8, thisID.length); 
         var answerControlName = 'answer' + sequence; 
         var answerControl = $(answerControlName); 
         if (answerControl)
         {
            if (answerControl.style.display == 'none')
            {
               answerControl.style.display = 'inline'; 
            }
            else
            {
               answerControl.style.display = 'none'; 
            }
         }  
      }
   }
   
}

