﻿
// 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 = 'hide';
	}
	for (var i = 0; i < questions.length; i++) {
		questions[i].className = '';
	}
}

// function for the link that turns them all on
function toggleAllOn(){
	for (var i = 0; i < answers.length; i++) { 
		answers[i].className = 'show';
	}
	for (var i = 0; i < questions.length; i++) {
		questions[i].className = 'activeDt';
	}
}
// targets next Sibling, the dd of the clicked dt 
function toggleNext(el) {
	var next=el.nextSibling;
	next.style.display=((next.style.display=="none") ? "block" : "none");
}

// reinitialize the scroll pane
function reinitScrollPane() {
	$('.v-scroll').jScrollPane({ scrollbarWidth:13, animateTo:true });
}

// show the first dd
function showFirst() {
	for (var i = 0; i < answers.length; i++) {
		answers[0].className = 'show';
	}
	for (var i = 0; i < questions.length; i++) {
		questions[0].className = 'activeDt';
	}
}

// initiated when id="faqSet" is found
// makes the dt's click-able when the page loads
function displayToggle(){
	toggleAllOff(); // turns all the answers off when the page is loaded
	showFirst(); // shows first entry
	reinitScrollPane();  // reinitialize the scroll pane
	for (i=0; i<questions.length; i++) { // loops through the questions a
		questions[i].onclick = function() { // shows the answers onclick
			if (this.className == "") {
				toggleAllOff(); // hides all dd's
				this.className = 'activeDt';
				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 == "hide") ? "show" : "hide"); // toggle class (visiblity)
				reinitScrollPane();
				$('.v-scroll')[0].scrollTo('.activeDt'); // scroll to the clicked dt
			} else {
				toggleAllOff(); // hides all dd's
				reinitScrollPane();
			}
		}
	}
}



