/*
Programmer: Darryl Ballard
Date created: 2009-04-06
Last updated: 2009-05-15
Version: 2.0.0

Requires:
	Prototype 1.6
	
Version History:
	2.0.0, 2009-05-15: Got it working.  Went with a completely anonymous function object.
	
	2.0.0 alpha, 2009-05-14: Trying a different object-oriented JS technique.
	
	1.0.0, 2009-05-14: Corrected and removed the alert if Prototype is missing.  It works fine, it's no longer alpha.
	
	1.0.0 alpha, 2009-04-06: Built.
*/

/* var GST_Flash_Messages2 = */ new function()
{
	var id_to_activate = "caught";
	var class_for_hover = "hover";
	var hide_parent_if_zero_visible_children = true;

	function handle_click()
	{
		this.hide();
		
		var visibleSiblings = 0;
		var siblings = this.parentNode.childElements();
		for (var i = 0; i < siblings.length; i++) {
			if (siblings[i].visible()) {
				visibleSiblings++;
			}
		}
		
		if (visibleSiblings == 0 && hide_parent_if_zero_visible_children) {
			this.parentNode.hide();
		}
	}
	
	function handle_mouseover()
	{
		this.addClassName(class_for_hover);
	}

	function handle_mouseout()
	{
		this.removeClassName(class_for_hover);
	}
	
	function init()
	{
		var objCaught = $(id_to_activate);
		
		if (objCaught) {
			// Give hover and click behavior to each child element
			var childElems = objCaught.childElements();
			for (var i = 0; i < childElems.length; i++) {
				var elem = childElems[i];
				elem.observe("click", handle_click);
				elem.observe("mouseover", handle_mouseover);
				elem.observe("mouseout", handle_mouseout);
			}
		}
	}
	
	if (typeof Prototype != "undefined") {
		document.observe("dom:loaded", init /* .bind(this) */);
	}
};
