// JavaScript Document for creating collapsible content
function toggleCollapsibleContainer(linkRef) {
	// Make sure the link ref is valid
	if (typeof linkRef == "string") {
		linkRef=document.getElementById(linkRef);
	}
	if (typeof linkRef == "undefined") return false;
	if (linkRef==null) return false;
	
	// Look for a parent object with the class name "collapsible_container"
	parentContainer=getFirstParentNodeOfClassName(linkRef, "collapsible_container");

	// Bail if a parent container couldn't be found.
	if (parentContainer==null) {
		window.alert("Error: closeCollapsibleContainer: Can't find parent.");
		return false;
	}
	
	// Figure out if the new state should be open or closed
	setOpen=true;
	if (containsClassName(parentContainer, "open")) {
		setOpen=false;
	}
	
	if (setOpen) {
		removeClass(parentContainer, "closed");
		addClass(parentContainer, "open");
	} else {
		removeClass(parentContainer, "open");
		addClass(parentContainer, "closed");
	}
}

// Set all links of a given class name to serve as triggers for collapsible containers
// If no className is passed, it'll assume "collapsible_controller"
function initCollapsibleContainers(className) {
	if (typeof className=="undefined") className="collapsible_controller";
	if (className==null) className="collapsible_controller";
	
	allLinks=getElementsByTagAndClassNames("a", className);
	assignOnClick(allLinks, function(){ toggleCollapsibleContainer(this); return false; })
}


function initCollapsibleNavigatorsOpen(className) {
	if (typeof className=="undefined") className="extra_navigators_open";
	if (className==null) className="extra_navigators_open";
	
	allLinks=getElementsByTagAndClassNames("a", className, "filterResults");
	assignOnClick(allLinks, function(){ toggleCollapsibleContainer(this); return false; })
}

function initCollapsibleNavigatorsClose(className) {
	if (typeof className=="undefined") className="extra_navigators_close";
	if (className==null) className="extra_navigators_close";
	
	allLinks=getElementsByTagAndClassNames("a", className, "filterResults");
	assignOnClick(allLinks, function(){ toggleCollapsibleContainer(this); return false; })
}