/**
 * uses prototype.js
 *
 * -> more information on http://www.prototypejs.org/api/
 */

// add the event for switching from open to closed to all sectionTitle elements
function sectionTitleInit(event) {
	sectionTitleElements = $$('div.sectionFrame6 h3');
	for(var i=0; i < sectionTitleElements.length; i++) {
		Event.observe(sectionTitleElements[i], 'click', sectionTitleSwitch);
	}
	
	sectionTitleElements = $$('div.sectionFrame8 h3');
	for(var i=0; i < sectionTitleElements.length; i++) {
		Event.observe(sectionTitleElements[i], 'click', sectionTitleSwitch);
	}
}

// switch the clicked element and close all others
function sectionTitleSwitch(event) {
	
	// if the user clicked on a closed element, close all and open this
	if(Element.hasClassName(this.parentNode, 'sectionFrame6')) {
		
		/*
		sectionTitleElements = $$('div.sectionFrame8 h3');
		
		for(var i=0; i < sectionTitleElements.length; i++) {
			Element.removeClassName(sectionTitleElements[i].parentNode, 'sectionFrame8');
			Element.addClassName(sectionTitleElements[i].parentNode, 'sectionFrame6');
		}
		*/
		
		Element.removeClassName(this.parentNode, 'sectionFrame6');
		Element.addClassName(this.parentNode, 'sectionFrame8');
		
	// if the user clicked on a open element, close this
	} else if(Element.hasClassName(this.parentNode, 'sectionFrame8'))  {
		Element.removeClassName(this.parentNode, 'sectionFrame8');
		Element.addClassName(this.parentNode, 'sectionFrame6');
	}
}


/**
 * This fixes the cutting off of the header when a hash is in the url.
 * @author: Tizian Schmidlin <st@cabag.ch>
 */

 // Set the height to fix. This might change from website to website.
var fixHeight = 16;
 
function fixHash() {
	// As some browsers may not support regular expressions, catch it if an error is thrown, else it could kill everything else
	try {
			// Check if there is a # in the href and if it is a non IE or IE >= 8
		if(/[^#]*#.*/.test(window.location.href) && (navigator.appName != 'Microsoft Internet Explorer'  || navigator.userAgent.indexOf('MSIE 8') != -1)) {
			
				// now get the id or anchor name
			hashEl = window.location.href.substring(window.location.href.indexOf('#')+1);
			//window.alert($$('a [name="'+hashEl+'"]'));
				// if it is an anchor
			if($$('a [name='+hashEl+']')) {
				ctArea = $$('#midCol .ctArea')[0];
				// Remove all top margins
				ctArea.style.marginTop="0px";
				// Replace it by some top padding
				ctArea.style.paddingTop=fixHeight+"px";
				if(navigator.vendor == 'Apple Computer, Inc.') {
					ctArea.style.paddingTop=(fixHeight-1)+"px";
				}else if (navigator.userAgent.indexOf('MSIE 8') != -1) {
					ctArea.style.paddingTop = (fixHeight-11)+"px";
				}
				// As the anchor check sometimes doesn't work in IE 8, do this
			}else if(document.getElementById(hashEl) && !$$('a [name='+hashEl+']')) {
				ctArea = $$('#midCol .ctArea')[0];
				
				// Remove all top margins
				ctArea.style.marginTop="0px";
				
				// Replace it by some top padding
				ctArea.style.paddingTop=fixHeight+"px";
					// Actually in Safari, the space isn't the same by 2px
				if(navigator.vendor == 'Apple Computer, Inc.') {
					ctArea.style.paddingTop=(fixHeight-1)+"px";
				}else if (navigator.userAgent.indexOf('MSIE 8') != -1) {
					ctArea.style.paddingTop = (fixHeight-11)+"px";
				}
			}
		}
	} catch(e) {}
}

function combinedInit(event) {
	sectionTitleInit(event);
	fixHash();
}

// run faqInit as soon as the page is ready
Event.observe(window, 'load', combinedInit);

