// JavaScript Document

function collapseAllSections() {
	if( document.getElementById ) {
		var divs = document.getElementsByTagName('DIV');
		for( i=0; i<divs.length; i++ ) {
			if( elementHasClassName(divs[i],'section') ) {
				// We've found a section.

				// Check the first childNode that is an element to see if it's a header.
				for( j=0; j<divs[i].childNodes.length; j++ ) {
					if( divs[i].childNodes[j].nodeName.indexOf('H') == 0 ) {
						// The section has a header, so we can proceed.
						var section = divs[i];
						var header = divs[i].childNodes[j];
						addClassName(header,'section');
						
						// Move the header *before* the section, so we can hide the section while leaving the header in place.
						section.removeChild(header);
						section.parentNode.insertBefore(header,section);
						
						// Add a twisty to the header, for toggling
						var control = document.createElement('A');
						var newText = document.createTextNode('[open]');
						control.appendChild(newText);
						control.title = 'open this section';
						control.className = 'closed';
						addEvent(control,'click',toggleSection);
						header.insertBefore(document.createTextNode(' '),header.firstChild); // a little spacing
						header.insertBefore(control,header.firstChild);
						
						// Hide the section
						section.style.display = 'none';
					
						break;
					}
					else if( divs[i].childNodes[j].nodeType == 1 ) {
						// First element is not a header, so quit.
						return false;
					}
				}
				
			}
		}
	}
}

function toggleSection(evt) {
	if (!evt) evt = window.evt // for IE/Win
	var control = findEventOwner(evt);
	var header = control.parentNode;
	
	// find section, which is the next element node
	var section = header.nextSibling;
	while( section.nodeName != 'DIV' ) {
		section = section.nextSibling;
	}
	
	if( elementHasClassName(control,'open') ) {
		section.style.display = 'none';
		removeClassName(control,'open');
		addClassName(control,'closed');
		control.title = 'open this section';
		var newText = document.createTextNode('close');
		control.replaceChild(newText,control.firstChild);
	}
	else if( elementHasClassName(control,'closed') ) {
		section.style.display = 'block';
		removeClassName(control,'closed');
		addClassName(control,'open');
		control.title = 'close this section';
		var newText = document.createTextNode('open');
		control.replaceChild(newText,control.firstChild);
	}
	
	return;
}
