///////////////// Show/hide script START /////////////////////

// SETTINGS FOR SHOW/HIDE SCRIPT
var linkColor = "#0099CC";  //set control link color
var nolinkColor = "#333333";  //set control link clicked-link color
var linkPadding = "10px 4px 15px 10px";  //set padding for control links
var ctrlBG = "#EDF1F4";  //set background color for the links in the control box
var ctrlMargin = "0px -10px 10px -10px";  //set margins for links in the control box
var txtdescbg = "white";  //set background color for the text description div
var txtdescBorder = "#CCCCCC";  //set border color for text description div
var txtdescPadding = "0px 10px 10px 10px"; //set padding for text description div

window.onload = startShowHide;
function startShowHide(){
// initialise and format the text description div when the page loads
	var controls = getElementsByClass('toggleCtrl');
	for ( i=0;i<controls.length;i++ ) {
	controls[i].style.display="block";
	controls[i].style.margin=ctrlMargin;
	controls[i].style.padding=linkPadding;
	controls[i].style.backgroundColor=ctrlBG;
	var links = controls[i].getElementsByTagName("a"); 
	links[0].style.color = nolinkColor;
	links[0].style.textDecoration = "none";	
	links[0].style.cursor = "text";	
	for( x=1;x<links.length;x++ ){
	  links[x].style.color = linkColor;
	  links[x].style.textDecoration = "none";
	  }
	}
//hide the content not visible on initial view
	var hide = getElementsByClass('hidden');
	for ( i=0;i<hide.length;i++ ) {
	hide[i].style.display = "none";
	}
//style the text description div(s)
	var textd = getElementsByClass('textdesc');
	for ( i=0;i<textd.length;i++ ) {
	textd[i].style.border = "1px solid";
	textd[i].style.borderColor = txtdescBorder;
	textd[i].style.width = "590px";
	textd[i].style.background = txtdescbg;
	textd[i].style.padding = txtdescPadding;
	}
}
///////////////////////////////////////////////////////////////
function toggle(toc,showhide){
	fixControls(toc);
	fixTxtDesc(showhide);
}
///////////////////////////////////////////////////////////////
function fixControls(toc){
	var list = toc.parentNode;
	//reset all links in the following loop
	for( i=0;i<list.childNodes.length;i++ ){
		if(list.childNodes[i].nodeType == 1){
		list.childNodes[i].style.color = linkColor;
		list.childNodes[i].style.cursor = "pointer";
		}
		}
	//change 'current' link so it doesn't look clickable
	toc.style.color = nolinkColor;
	toc.style.cursor="text";
}
///////////////////////////////////////////////////////////////
function fixTxtDesc(showhide){
// Create an array of all DIV elements within the current text description block
var showdiv = document.getElementById(showhide).parentNode;
var elements = showdiv.getElementsByTagName("div");
// Hide all DIV elements in the text description block except for the first control DIV
for( i=1;i<elements.length;i++ ){
	elements[i].style.display = "none";
	}
// Show the correct DIV
var contentToShow = document.getElementById(showhide);
contentToShow.style.display = "block";
showChildren(contentToShow);
}
///////////////////////////////////////////////////////////////
function showChildren(x){
// Display nested DIVS (if any)
var divs = x.getElementsByTagName("div");
	for( i=0;i<divs.length;i++ ){
	divs[i].style.display = "block";
	}
}

///////////////// Show/hide script END /////////////////////

function getElementsByClass(searchClass,node,tag) {
// this code snippet returns an array of elements using the specified class
// accepts 3 arguments - the class name, specific node type to look for (default 'document'), and tag (ie 'div')
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}