// functions to toggle divs
var toggleDivClassName = "toggleable";
var toggleDivSpeedMultiplier = 2;
var toggleDivDelay = 30;

var toggleDivs = new Array();
var togglingDivs = new Object();

// The initial function that handles the request to toggle a DIV
function toggleDiv(divId,action) {
	var d = document.getElementById(divId);
	if (d==null || d.tagName!="DIV" || !d.offsetHeight || togglingDivs[divId]) { return; }

	d.style.overflow = "hidden";
	if (action=="open" || (typeof(action)=="undefined" && d.style.visibility=="hidden")) {
		// open it
		var originalHeight = d.offsetHeight;
		var height = 1;
		d.style.height = height+"px";
		d.style.visibility = "visible";
		d.style.position="static";
		togglingDivs[divId] = true;
		setTimeout("toggleObject('"+divId+"','open',"+originalHeight+","+height+")",toggleDivDelay);
	}
	else if (action=="close" || (typeof(action)=="undefined" && d.style.visibility=="visible")) {
		// close it
		var originalHeight = d.offsetHeight;
		var height = originalHeight;
		togglingDivs[divId] = true;
		setTimeout("toggleObject('"+divId+"','close',"+originalHeight+","+height+")",toggleDivDelay);
	}	
}

// The function that is called repeatedly until the toggle is done
function toggleObject(divId, openClose, originalHeight, height) { 
	var d = document.getElementById(divId);
	if (d==null || d.tagName!="DIV") { return; }
	
	if (openClose=="open") {
		height = height * toggleDivSpeedMultiplier;
		if (height > originalHeight) {
			d.style.height = originalHeight+"px";
			delete togglingDivs[divId];
		}
		else {
			d.style.height = height+"px";
			setTimeout("toggleObject('"+divId+"','"+openClose+"',"+originalHeight+","+height+")",toggleDivDelay);
		}
	}
	else {
		height = height * (1/toggleDivSpeedMultiplier);
		if (height <= 1) {
			d.style.position = "absolute";
			d.style.visibility = "hidden";
			d.style.height = originalHeight+"px";
			delete togglingDivs[divId];
		}
		else {
			d.style.height = height+"px";
			setTimeout("toggleObject('"+divId+"','"+openClose+"',"+originalHeight+","+height+")",toggleDivDelay);
		}
	}
}

// A function which is called onload of the window, to hide all the toggle divs initially. This is done
// so that non-JS browsers will see the divs rather than have them be hidden.
function hideToggleDivs() {
	var divs = document.getElementsByTagName("DIV");
	for (var i=0; divs!=null && i<divs.length; i++) {
		if (divs[i].className.indexOf(toggleDivClassName)>-1) {
			toggleDivs[toggleDivs.length] = divs[i];
			var s = divs[i].style;
			s.position="absolute";
			s.visibility="hidden";
		}
	}
}