// start by getting all the questions and answers
// these will be put into arrays

var questions = document.getElementsByTagName('dt');
var answers = document.getElementsByTagName('dd');


// function for the link that turns them all off
function toggleAllOff(){
  for (var i = 0; i < answers.length; i++) { 
    answers[i].className = 'hidden';
    questions[i].innerHTML = "+" + questions[i].innerHTML.substring(1, questions[i].innerHTML.length);
  }
}

// function for the link that turns them all on
function toggleAllOn(){
  for (var i = 0; i < answers.length; i++) { 
    answers[i].className = 'show';
    questions[i].innerHTML = "-" + questions[i].innerHTML.substring(1, questions[i].innerHTML.length);
  }
}


function toggleNext(el) {
 var next=el.nextSibling;
 next.style.display=((next.style.display=="none") ? "block" : "none");
}


//makes the definition lists click-able
function displayToggle(){  
   for (i=0; i<questions.length; i++) { // loops through the questions a
     // sets up <dt> onclick event handler
     questions[i].onclick=function() { // shows the answers onclick
          var next = this.nextSibling;
          while(next.nodeType != 1) next=next.nextSibling; // if it gets to a non-element node, go to the next one
          next.className=((next.className=="hidden") ? "show" : "hidden");
          // toggles + and - on <dt>
         if (this.innerHTML.charAt(0)=="+"){
          this.innerHTML = "-" + this.innerHTML.substring(1, this.innerHTML.length);
         }else{
          this.innerHTML = "+" + this.innerHTML.substring(1, this.innerHTML.length);
         }         
    }  // end of onclick function definition
   }   
}

// initiates the click-able dt's when the page loads
function init() { 
  document.getElementById('allLinks').className="show";  // display show and hide all links
  for (i=0; i<questions.length; i++) {
    // add + to start of <dt> text  
   	questions[i].innerHTML = "+ " + questions[i].innerHTML.substring(0, questions[i].innerHTML.length);
  }
  displayToggle();  // make the definition lists click-able
  toggleAllOff();  // calls the toggle all off function to turn all the answers off when the page is loaded  

}
  
  function displayLinkedAnswer(id){
  	for (i=0; i<questions.length; i++) { // loops through the questions a
     if (questions[i].id == id ){
     	answers[i].className = 'show bold'; 
        questions[i].innerHTML = "-" + questions[i].innerHTML.substring(1, questions[i].innerHTML.length);
      	location.href = "#"+id;     	
     } 
     else if(answers[i].className == 'show bold'){
     	answers[i].className = 'show';     
     }
    }  
    return false;
  }
  
  



