/*
Programmer: Darryl Ballard
Date created: 2009-04-16
Last updated: 2009-04-16
Version: 1.0

Requires:
	Prototype 1.6
	
Version History:
	2009-04-16: Started?
*/

var GST_Toggleable_Definition_Lists = {
	class_to_activate:"toggleable",
	class_when_activated:"scripted",
	term_class_on_hover:"hover",
	definition_class_when_hidden:"hidden",
	
	activate:function() {
		// Loop through all the definition lists requesting toggleability
		var lists = $$("dl." + GST_Toggleable_Definition_Lists.class_to_activate);
		for (var i = 0; i < lists.length; i++) {
			// Mark this list as javascript-enhanced
			lists[i].addClassName(GST_Toggleable_Definition_Lists.class_when_activated);
			
			// Activate the terms
			var terms = lists[i].select("dt");
			for(var m = 0; m < terms.length; m++) {
				terms[m].observe("mouseover", function() {
					this.addClassName(GST_Toggleable_Definition_Lists.term_class_on_hover);
				});
				
				terms[m].observe("mouseout", function() {
					this.removeClassName(GST_Toggleable_Definition_Lists.term_class_on_hover);
				});
				
				var objNextDef = terms[m].next("dd");
				if (objNextDef) {
					objNextDef.addClassName(GST_Toggleable_Definition_Lists.definition_class_when_hidden);
				}
				
				terms[m].observe("click", function() {
					var obj = this.next("dd");

					if (obj.hasClassName(GST_Toggleable_Definition_Lists.definition_class_when_hidden)) {
						obj.removeClassName(GST_Toggleable_Definition_Lists.definition_class_when_hidden);
					} else {
						obj.addClassName(GST_Toggleable_Definition_Lists.definition_class_when_hidden);
					}
				});
			} // terms
		} // lists
	} // activate()
}

// Require that Prototype is available
if (typeof Prototype != "undefined") {
	document.observe("dom:loaded", GST_Toggleable_Definition_Lists.activate);
}
