/*
 * date:	2003-01-23
 * info:	http://inspire.server101.com/js/xc/
 */

var xcNode = [];

function xcSet(m, c) {
if (document.getElementById && document.createElement) {
	var u = document.getElementById(m);
	//var v = document.getElementById(m).getElementsByTagName('ul');
	m = document.getElementById(m).getElementsByTagName('ul');

	
	//var v1 = u.getElementsByTagName('div'); 
	//alert (v1.length);


	var d, p, x, h, i, j;
	for (i = 0; i < m.length; i++) {
		if (d = m[i].getAttribute('id')) {
			//alert (m[i].id);
			xcCtrl(d, c, 'x', '[+]', 'Show', m[i].getAttribute('title')+' (expand menu)');
			x = xcCtrl(d, c, 'c', '[-]', 'Hide', m[i].getAttribute('title')+' (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'];
				}
			}

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

	var u2 = $(u).immediateDescendants();
	for(var j=0; j < u2.length ; j++)
	{
		if ($(u2[j]).hasClassName('xc') == false)
		{
			$(u2[j]).remove();
		}
		else
		{
			var u3 = $(u2[j]).immediateDescendants();
			for(var k=0; k < u3.length ; k++)
			{
				if (u3[k].tagName == 'A')
				{
					var u6 = $(u3[k]).nextSiblings();
					u6[0].style.display = 'block';
					var u7 =  u6[0].getElementsByTagName('strong');
					/*if(u7[0])
					{
						var u8 = u7[0].parentNode;
						//alert (u8.href);
						var u10 = $(u8).previousSiblings();
						//alert (u10[0].tagName);
						var u11 = u10[0].getElementsByTagName('a');
						//alert (u11[0].href);
						var oldhref = u11[0].href
						//var newhref = oldhref.replace(/Show/i, "Hide");
						//xcCtrl(d, c, 'c', '[-]', 'Hide', m[i].getAttribute('title')+' (collapse menu)');
						//alert (newhref);
						//u11[0].href = newhref;
						var u9 = (u8).nextSiblings();
						var catid1 = u9[0].id;
						//xcShow(33)
						//alert(catid1);
						//xcCtrl(catid1, 'xc', 'x', '[+]', 'Show', m[i].getAttribute('title')+' (expand menu)');
						//xcHide(catid1);
						//xcXC(catid1,'none','xcx', 'xcc');
						u9[0].style.display = 'block';
						//xcHide(catid1);
					}*/

					u3[k].style.display = 'none';
					var u5 = $(u3[k]).previous(0);
					u5.style.display = 'none';
					var u4 = $(u3[k]).immediateDescendants();
					if (u4.length == 0)
					{
						$(u2[j]).remove();
					}
				}
			}
		}
	}
}


function xcShow(m) {
	xcXC(m, 'block', m+'c', m+'x');
	m1 = document.getElementById(m);
	//alert (m1.id);
	par1 = document.getElementById(m).parentNode;
	par2 = par1.parentNode;
	var chi = $(par2).immediateDescendants();
	for(var m=0; m < chi.length ; m++)
	{
		//var selected = chi.getElementById(m1.id);
		//var allul = $(chi[m]).immediateDescendants();
		//alert (allul.tagName);
		if (chi[m] != par1)
		{
			var mm = chi[m].getElementsByTagName('ul')[0].id;
			xcHide(mm);
		}

	}
}


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]);
	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 b = document.getElementById(m);
var b1 = $(b).previous('a');
//var b2 = $(b).previous('div');
b1.href = 'javascript:xcShow(\''+m+'\');';


	var d = document.createElement('div');
	d.className = c+s;
	d.appendChild(a);
	var dd=d;
	//alert (d.tagName);
	//dd.nextSibling.href = 'javascript:xc'+f+'(\''+m+'\')';
	return xcNode[m+s] = d;
}
