/*
PRELOAD THE ARROWS
*/

if (document.images) {
img1 = new Image();
img1.src = "images/arrow_gn_dn.gif";
img2 = new Image();
img2.src = "images/arrow_bl_dn.gif";
img3 = new Image();
img3.src = "images/arrow_or_dn.gif";
img4 = new Image();
img4.src = "images/arrow_bn_dn.gif";
img5 = new Image();
img5.src = "images/arrow_rd_dn.gif";
img6 = new Image();
img6.src = "images/arrow_dn.gif";
}

/*
TOGGLER
*/

// global variables used in scripts on this page 
// they refer to the class names you can see above.
	var opcn="open";
	var clocn="closed";
	var ccn="clicker";
	var tcn="target";
	var icn="inline";

// this is used by other scripts here to set the clickers as open or closed 
// and to hide or show the next sibling
function toggleNext(el,target,thedisplay) {
	if (target=='next') {var next=el.nextSibling}
	else if (target=='child') {var next=el.firstChild}
			el.className=el.className.replace(new RegExp(opcn+"\\b"), "");
			el.className=el.className.replace(new RegExp(clocn+"\\b"), "");
			while(next.nodeType != 1 && next.nextSibling) next = next.nextSibling;
			if (next.style) {
			next.style.display=((next.style.display=="none") ? thedisplay : "none");
			el.className+=((next.style.display==thedisplay)? " "+opcn : " "+clocn);
			}
			else {
			el.className=el.className.replace(new RegExp(ccn+"\\b"), "");
			}
			if (next.nodeType==1) {
			var rE = new RegExp("(^|\\s)" + tcn + "(\\s|$)");
					if (!rE.test(next.className)) {next.className+=" "+tcn}
					if (target=="child") {
					var rE = new RegExp("(^|\\s)" + icn + "(\\s|$)");
					if (!rE.test(next.className)) {next.className+=" "+icn}
						}
					}
}

// this gets the elements by tag and ID (together) and sets the function above
// to run onclick
function toggleByIdAndTag(el,tname,target,thedisplay) {
	clickers=document.getElementById(el).getElementsByTagName(tname);
	for (i=0; i<clickers.length; i++) {
		clickers[i].className+=" "+ccn;
		clickers[i].onclick=function() {toggleNext(this,target,thedisplay)}
		toggleNext(clickers[i],target,thedisplay);
	}
}

//This one should get all elements (ggkids) with a certain className within a certain ID.
function getAllElementsByIdThenClassName(id,cname) {
var nodes = document.getElementById(id).childNodes;
var cEls = new Array();
for (i=0; i<nodes.length; i++) {
var rE = new RegExp("(^|\\s)" + cname + "(\\s|$)");
	if (nodes[i].className) {
		if (rE.test(nodes[i].nodeType==1)) {
			cEls.push(nodes[i]);
			}
		}
	if (nodes[i].hasChildNodes()==true) {
		var gkids=nodes[i].childNodes;
		for (j=0; j<gkids.length; j++) {
				if (gkids[j].nodeType==1) {
					if (rE.test(gkids[j].className)) {
					cEls.push(gkids[j]);
					}
				}
			if (gkids[j].hasChildNodes()==true) {
				var ggkids=gkids[j].childNodes;
				for (k=0; k<ggkids.length; k++) {
						if (ggkids[k].nodeType==1) {
							if (rE.test(ggkids[k].className)) {
							cEls.push(ggkids[k]);
							}
						}
					}
				}
			}
		}
	}
return cEls;
}


function hideAll(id,hide) {
var hideb=document.getElementById(hide);
hideb.onclick=function() {
	var targets=new Array();
	targets=getAllElementsByIdThenClassName(id,tcn);
	for (i=0; i<targets.length; i++) {
		if (targets[i].nodeType==1) {targets[i].style.display="none";}
		}
	var clickers=new Array();
	clickers=getAllElementsByIdThenClassName(id,ccn);
	for (i=0; i<clickers.length; i++) {
		clickers[i].className=clickers[i].className.replace(new RegExp(opcn+"\\b"), "");
		clickers[i].className=clickers[i].className.replace(new RegExp(clocn+"\\b"), "");
		clickers[i].className+=" "+clocn;
		}
	}
}

function showAll(id,show) {
var showb=document.getElementById(show);
showb.onclick=function() {
	var targets=new Array();
	targets=getAllElementsByIdThenClassName(id,tcn);
	for (i=0; i<targets.length; i++) {
		if (targets[i].style) {
			var rE = new RegExp("(^|\\s)" + icn + "(\\s|$)");
				if (rE.test(targets[i].className)) {targets[i].style.display="inline"}			
				else {
				targets[i].style.display="block";
				}
			}
		}
	var clickers=new Array();
	clickers=getAllElementsByIdThenClassName(id,ccn);
	for (i=0; i<clickers.length; i++) {
		clickers[i].className=clickers[i].className.replace(new RegExp(opcn+"\\b"), "");
		clickers[i].className=clickers[i].className.replace(new RegExp(clocn+"\\b"), "");
		clickers[i].className+=" "+opcn;
		}
	}
}


// this just gets the ball rolling
function start(id,tname1,target1,thedisplay1,tname2,target2,thedisplay2,hide,show) {
toggleByIdAndTag(id,tname1,target1,thedisplay1)
toggleByIdAndTag(id,tname2,target2,thedisplay2)
hideAll(id,hide)
showAll(id,show)
}

