// to cater for customised submenu items to show onmouseover 
//function calls are from navigation.xsl
//originally display is hidden by css although the siteconf.xml sets the subitems to be shown.
//INFO: js is used instead of just css to show and hide items on hover because IE6 can't do it
//IMPORTANT: only works for menu with the folder as parent (see navigation document)
//IMPORTANT: in siteconf.xml, contextualised menu MUST BE FALSE

//Originally Nik used js to load pictures into pages other than home
//This is very hard to maintain and anyway easier to do by 'including' sub documents
//BB has deleted all parts of this script related to loading pictures
//A backup of Nik's original js is kept on the server in its original location

//It would be good to adapt this so that only the next level down of the menu is displayed
function displaySubItems(item) {
	var navtree = document.getElementById(item);
	var subitems = navtree.getElementsByTagName('ul');
	subitems[0].style.display = 'block';
}

function hideSubItems(item) {
	var navtree = document.getElementById(item);
	var subitems = navtree.getElementsByTagName('ul');
	subitems[0].style.display = 'none';	
}

//for FAQ section
function toggleShowHide(element) {
	element = document.getElementById(element);

	if (element.style.display != 'none') {
		element.style.display = 'none';
	}
	else {
		element.style.display = 'block';
	}
}

//page onload stuff 
function pageSetup() {

	var url = window.location.href;
		
	// FAQ
	if (url.match(/faq/i) ) faqFoldAll(); 
	}		

function faqFoldAll() {
		/* -------------------------------------------
		accessibility stuff - set default FAQ answers to show, 
		but hide with javascript page onload- this is important when there is no js 
		--------------------------------------------*/
		faqA = getElementsByClass("faq-Answer");
		for (i=0; i < faqA.length; i++) {
				faqA[i].style.display = 'none';
			}
}


function getElementsByClass(searchClass,node,tag) {
	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;
}

