// (c)2005 Internova UK Ltd
// Written by Jamie Sanders

//Initialise menu object
//Extra style functionality and browser compatability issues can be added here
var menu = {
	getElement:	function(id) {
				if (document.getElementById) {
					return document.getElementById(id);
				}
			},
	getStyle:	function(id) {
				return menu.getElement(id).style;
			},
	show:		function(id) {
				menu.getStyle(id).visibility = 'visible';
				menu.getStyle(id).display = 'block';

			},
	hide:		function(id) {
				menu.getStyle(id).visibility = 'hidden';
				menu.getStyle(id).display = 'none';
			}
}

//Setup onload variables
var strExpandedID = new Array(menu.Branches);
var intBranch = 0;
var countBranches;
var boolCollapse = false;

//Main routine
function Expand(id, branch) {
	//collapses all the branches of the previous menu open when a different branch is clicked
	if (intBranch != 0 && strExpandedID[intBranch] != id && branch <= intBranch) {
		if (branch < intBranch) {
			for (countBranches = branch; countBranches <= intBranch; countBranches ++) {
				if (strExpandedID[countBranches] != '') {
					menu.hide(strExpandedID[countBranches]);
				}
			}
			boolCollapse = true;
		} else {
			menu.hide(strExpandedID[branch]);
		}
	}
	//either hides or shows the menu clicked on (hides if the menu clicked is already open)
	if ((menu.getStyle(id).visibility == 'visible') || (boolCollapse && strExpandedID[branch] == id)) {
		menu.hide(id);
	} else {
		menu.show(id);
	}
	//resets the variables for use on next click
	strExpandedID[branch] = id;
	intBranch = branch;
	boolCollapse = false;
}
