if (window.attachEvent) {
	window.attachEvent("onload",faculty_init);
}
else if (window.addEventListener) {
	window.addEventListener("load",faculty_init,true);
}


function faculty_init() {
	var faculty = getElementsByClassName("faculty",document,"div"), flen = faculty.length, i;
	if (faculty.length < 1)
		return;
		
	for (i = 0; i < flen; i++) {
		var j, profs = faculty[i].getElementsByTagName("b"), plen = profs.length;	
		for (j = 0; j < plen; j++) {
			profs[j].style.paddingLeft = "15px";
			profs[j].style.cursor = "pointer";
			profs[j].nextSibling.nextSibling.style.visibility = "hidden";
			profs[j].nextSibling.nextSibling.style.overflow = "hidden";
			profs[j].nextSibling.nextSibling.style.height = "0px";
			//profs[j].nextSibling.nextSibling.style.marginBottom = "0px";
			profs[j].onclick = function() {faculty_toggle(this.previousSibling)};
			
			var toggler2 = document.createElement("em");
				toggler2.className = "toggler";
				toggler2.onclick = function() {faculty_toggle(this)};
			
			profs[j].parentNode.insertBefore(toggler2,profs[j]);
		}
	}
}

function faculty_toggle(obj) {
	var block = obj.nextSibling.nextSibling.nextSibling;
	block.style.visibility = (obj.style.backgroundImage.toString().indexOf("collapse") >= 0) ? "hidden" : "visible";
	
	if (block.style.visibility == "hidden") {
		obj.style.backgroundImage = "url(../images/expand.png)";
		block.style.height = "0px";
	}
	else {
		obj.style.backgroundImage = "url(../images/collapse.png)";
		block.style.height = "100%";
	}
}

function getElementsByClassName(cls,root,tag) {
	if (!root)
		root = document;
	if (!tag)
		tag = "*";
		
	var x = root.getElementsByTagName(tag), len = x.length, i, arr = new Array();
	for (i = 0; i < len; i++) {
		if (x[i].className == cls)
			arr.push(x[i]);
	}
	
	return arr;
}	
