// JavaScript Document
window.onload = initPage;  
function initPage() {
  setWindowClose();
  setToggle();
}
function setWindowClose() {
  var links=document.getElementsByTagName("a");//find all <a>
  for (var i=0; i < links.length; i++){
	  if (links[i].className == "close_button"){
		  links[i].onclick=function() {//sets onclick event listener on <a> tags
			window.close();
			return false;
		  }
	  }
  }
}
function setToggle() {
  var links=document.getElementsByTagName("a");//find all <a> tags
  for (var i=0; i < links.length; i++){
	  if (links[i].className == "question"){//looks for any link with a css class of question
		  links[i].onclick=function() {//sets onclick event listener
			var linkId = this.id;//get link id
			var answerId = linkId + "A";//Add "A" to link id to get related answer id;
			openClose = new toggleElement(linkId,answerId)//calls a new toggleElement object
			openClose.toggle()
			return false;
			}
		  }
	  }
  }
  
function toggleElement(linkId,answerId){//Checks state and open or closes answer element.
	this.linkId = linkId;
	this.answerId = answerId;
	this.toggle = function (e) {
		if (document.getElementById(this.linkId).className == "question"){
			document.getElementById(this.linkId).className = "question_on";
			document.getElementById(this.answerId).className = "answer_on";
		}
		else{
			document.getElementById(this.linkId).className = "question";
			document.getElementById(this.answerId).className = "answer";
		}
	}
}

