/*
Programmer: Darryl Ballard
Date created: 2009-04-16
Last updated: 2010-05-13
Version: 2.0

Requires:
	Prototype 1.6
	
Version History:
	2010-05-13: No more GST_Toggleable_Definition_Lists in the global namespace,
		removed the hover code, as most browsers can do that with CSS, and a
		hover javascript can handle the rest.  Remove the "closed" class.  Added
		an "opened" class.  Also applies the opened class to the dt, to allow
		for open/closed indication in only the dt (e.g. +/- icon)
	
	2009-04-16: Started?
*/

// Require that Prototype is available
if (typeof Prototype != "undefined") {
	document.observe("dom:loaded", function() {
		var class_to_activate = "toggleable";
		var class_when_activated = "scripted";
		var class_when_open = "open";
		
		var handle_term_click = function() {
			var nextDD = this.next("dd");
			
			if (this.hasClassName(class_when_open)) {
				// Close this and the following dd
				this.removeClassName(class_when_open);
				if (nextDD) {
					nextDD.removeClassName(class_when_open);
				}
			} else {
				// Open this and the following dd
				this.addClassName(class_when_open);
				if (nextDD) {
					nextDD.addClassName(class_when_open);
				}
			}
			
		};
		
		// Init
		var allToggleableLists = $$("dl." + class_to_activate);
		var i, il;
		var j, jl;
		var dts, dds;
		for (i = 0, il = allToggleableLists.length; i < il; i++) {
			// Mark this list as javascript-enhanced
			allToggleableLists[i].addClassName(class_when_activated);
			
			// Activate the terms
			dts = allToggleableLists[i].select("dt");
			for (j = 0, jl = dts.length; j < jl; j++) {
				dts[j].observe("click", handle_term_click);
			}
			
		}
	});
}

