/*******************************************************************************
 * 						EXPAND / COLLAPSE SECTIONS
 * 
 * Source: http://jdstiles.com/java/expandcollapsesections.html
 * 
 * Completely modified by MW on 2006-02-22. 
 ******************************************************************************/    

// initializing function...
function expand_collapse_createDocumentStructure (containerID, headerTagName, imagepath_expand, imagepath_collapse, header_padding_left, scrolldown) {
	/***************************************
	 * @param containerID: 			id of the the container div. Headers outside this div are not being considered.
	 * @param headerTagName:		Name of the header tag, e.g. 'h2'.
	 * @param imagepath_expand:		Image path to the expand image, e.g. 'images/plus.png'.
	 * @param imagepath_collapse:	Image path to the collapse image, e.g. 'images/minus.png'.
	 * @param header_padding_left: 	Padding left of	the header, e.g. '14px'.
	 * @param scrolldown:			No. of pixels to scroll down. Use 0 or false to deactivate	 	 
	 * -------------------------------------------------------------------------
	 * Exampe for calling:
	 *		<script type="text/javascript"><!--
	 *			expand_collapse_createDocumentStructure('container', 'h2', 'images/plus.png', 'images/minus.png', '14px');
	 *		// --></script>	 	 	 	  
	 **************************************/ 		

	if (document.getElementsByTagName) {

		var containerElem = document.getElementById(containerID);
		var elements = containerElem.getElementsByTagName(headerTagName);

		var collapseDivs = new Array(elements.length);

		for (var i = 0; i < elements.length; i++) {
			var element = elements[i];
			var siblingContainer;
			if (document.createElement && (siblingContainer = document.createElement('div')) && siblingContainer.style) {
				var nextSibling = element.nextSibling;
				element.parentNode.insertBefore(siblingContainer, nextSibling);
				var nextElement = elements[i + 1];
				while (nextSibling != nextElement && nextSibling != null) {
					var toMove = nextSibling;
					nextSibling = nextSibling.nextSibling;
					siblingContainer.appendChild(toMove);
				}
				siblingContainer.style.display = 'none';

		        collapseDivs[i] = siblingContainer;
        
				// Modify header style
				element.style.backgroundImage = 'url(' + imagepath_expand + ')';					
				element.style.backgroundRepeat = 'no-repeat';
				element.style.backgroundPosition = '0 50%';
				element.style.paddingLeft = header_padding_left;
				element.style.cursor = 'pointer';
				element.onclick = collapseExpandLink;

				// Variablen zuweisen, damit Zugriff in der Zielfunction bei onclick abgreifbar sind...
				element.style_imagepath_expand = imagepath_expand;
				element.style_imagepath_collapse = imagepath_collapse;
				element.scrolldown_if_expand = scrolldown;
			}
      		else {
        		// no dynamic creation of elements possible
        		return;
      		} // if
    	} // for
	} // if
}

function collapseExpandLink (evt) {
	if (this.nextSibling.style.display == 'none') {
		this.style.backgroundImage = 'url(' + this.style_imagepath_collapse + ')';
		this.nextSibling.style.display = ''
		// scroll down?
		if ( (this.scrolldown_if_expand != false) || (this.scrolldown_if_expand != 0) ) {
			scrollBy(0,this.scrolldown_if_expand); // scroll down after section was being opened
		}
	}
	else {
    	this.style.backgroundImage = 'url(' + this.style_imagepath_expand + ')';
		this.nextSibling.style.display = 'none'
  	}
	if (evt && evt.preventDefault) {
    	evt.preventDefault();
	}
	return false;
}
