/**********************************************
 * Toggle A-to-Z Result Details
 * (These effects use prototype.list.js and
 *	moo.fx.pack.js, found in /scripts)
 **********************************************/

// Initialization of toggling effects
var toggleDetails;
var results = new Array();
var details = new Array();
var numResults = 0;

// Set the speed of toggle transitions (in ms)
var speed = 250;

// The toggleIcons function takes as a parameter a details DIV
// (called by the Accordion effect).
// If the class of the H4 is "active", it clears it.
// If the class of the H4 is "", it sets it to "active"
function toggleIcons(el) {
	// Get the H4 associated with the DIV
	r = el.parentNode.getElementsByTagName("h4")[0];
	
	// Toggle the class="active" state of the H4
	if(r.className == "") {
		r.className = "active";
	}
	else {
		r.className = "";
	}
}

// If the browser supports getElementById(), set up the toggling effects
if(document.getElementById) { 
	window.onload = function() {
		// Step 1: count the number of results on the page
		h4s = document.getElementsByTagName("h4");
		for(i = 0; i < h4s.length; i++) {
			if(h4s[i].id != "" && h4s[i].id.substr(0, 6) == "result")
				numResults++;
		}
		
		// Step 2: go through the results (H4's) and clear the class attribute.
		// Class is set to "active" by default so that content looks correct for 
		// browsers with JavaScript disabled. Also populate results and details arrays.
		for(i = 1; i <= numResults; i++) {
			r = document.getElementById("result"+i);
			r.className = "";	// clear class="active"
			results[i-1] = (document.getElementById("result"+i));
			details[i-1] = (document.getElementById("details"+i));
		}
		
		// Step 3: initalize the "accordion" effect using the arrays of 
		// results and details set up in Step 1.
		toggleDetails = new fx.Accordion(results, details, { duration: speed, height: true, width: false, opacity: false, onComplete: function(element) { toggleIcons(element); }});
	}
}

