/*
 * file:	xc.js
 * date:	2002-08-21
 * info:	http://inspire.server101.com/js/xc/
 */


// +/- nodes
var xcNode = [];


// setup menu (id, class [, ids expanded])
function xcSet(ul, c) {
	// DOM?
	if (document.getElementById) {
		// menu
		ul = document.getElementById(ul).getElementsByTagName('ul');
		var id, p, x, h, i, j;
		for (i = 0; i < ul.length; i++) {
			// id?
			id = ul[i].getAttribute('id')
			if (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)');

				// hide?
				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
function xcXC(e, d, s, h) {
	e = document.getElementById(e);
	e.style.display = d;
	e.parentNode.replaceChild(xcNode[s], xcNode[h]);
	xcNode[s].firstChild.focus();
}

// +/- nodes
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;
}