/*
 * date:	2003-01-23 (modified 2006-09-24 to support expand/collapse on link)
 * info:	http://inspire.server101.com/js/xc/
 */

var xcNode = [];

function xcSet(m, c) {
if (document.getElementById && document.createElement) {
	m = document.getElementById(m).getElementsByTagName('ul');
	var d, p, x, l, h, i, j, t;
	for (i = 0; i < m.length; i++) {
		if (d = m[i].getAttribute('id')) {
			t = m[i].getAttribute('title');
			xcCtrl(d, c, 'x', '[+]', 'Show', t+' (expand menu)');
			xcCtrl(d, c, 'xl', t, 'Show', t+' (expand menu)');
			x = xcCtrl(d, c, 'c', '[-]', 'Hide', t+' (collapse menu)');
			l = xcCtrl(d, c, 'cl', t, 'Hide', t+' (collapse menu)');

			p = m[i].parentNode;
			if (h = !p.className) {
				j = 2;
				while ((h = !(d == arguments[j])) && (j++ < arguments.length));
				if (h) {
					m[i].style.display = 'none';
					x = xcNode[d+'x'];
					l = xcNode[d+'xl'];
				}
			}

			p.className = c;
			p.replaceChild(l, p.firstChild);
			p.insertBefore(x, p.firstChild);
		}
	}
}}


function xcShow(m) {
	xcXC(m, 'block', m+'c', m+'x');
}


function xcHide(m) {
	xcXC(m, 'none', m+'x', m+'c');
}


function xcXC(e, d, s, h) {
	e = document.getElementById(e);
	e.style.display = d;
	e.parentNode.replaceChild(xcNode[s], xcNode[h]);
	e.parentNode.replaceChild(xcNode[s+'l'], xcNode[h+'l']);
	xcNode[s].firstChild.focus();
}


function xcCtrl(m, c, s, v, f, t) {
	var a = document.createElement('a');
	a.setAttribute('href', 'javascript:xc'+f+'(\''+m+'\');');
	a.setAttribute('title', t);
	a.appendChild(document.createTextNode(v));

	var d = document.createElement('div');
	d.className = c+s;
	d.appendChild(a);

	return xcNode[m+s] = d;
}
