/*
 * file:	xc.js
 * date:	2002-05-31
 * info:	expand/collapse menu
 */


// +/- nodes
var xcNode = [];


// set - setup menu, call with: id, class [, ids to be expanded]
function xcSet(ul, c) {
	// standards support?
	if (!document.getElementById) {
		return false;
	}

	// get menu items
	ul = document.getElementById(ul).getElementsByTagName('ul');
	var id, p, x, h, i, j;
	for (i = 0; i < ul.length; i++) {

		// only control if id present
		if (id = ul[i].getAttribute('id')) {
			// +/- controls
			x = xcCtrl(id, c, 'x', '[+]', 'Show', ul[i].getAttribute('title') + ' (expand menu)');
			x = xcCtrl(id, c, 'c', '[-]', 'Hide', ul[i].getAttribute('title') + ' (collapse menu)');

			// check against items left open
			h = true;
			j = 2;
			while ((h = !(id == arguments[j])) && (j++ < arguments.length));
			if (h) {
				ul[i].style.display = 'none';
				x = xcNode[id + 'x'];
			}

			// parent
			p = ul[i].parentNode;
			p.className = c;
			p.insertBefore(x, p.firstChild);
		}
	}
}

// expand
function xcShow(id) {
	xcXC(id, 'block', id + 'c', id + 'x');
}

// collapse
function xcHide(id) {
	xcXC(id, 'none', id + 'x', id + 'c');
}

// toggle state
function xcXC(e, d, s, h) {
	e = document.getElementById(e);
	e.style.display = d;
	e.parentNode.replaceChild(xcNode[s], xcNode[h]);
	xcNode[s].focus();
}

// +/- controls
function xcCtrl(id, c, xc, pm, sh, t) {
	var x = document.createElement('a');
	x.setAttribute('href', 'javascript:xc' + sh + '(\'' + id + '\');');
	x.setAttribute('title', t);
	x.appendChild(document.createTextNode(pm));

	var d = document.createElement('div');
	d.className = c + xc;
	d.appendChild(x);

	return xcNode[id + xc] = d;
} 
