
/* Function scrollOut() is a preparation function for scrolling components in/out of view.
 * Actual scrolling is done by scrollOutTimed(). This function simply determines which
 * element to scroll and whether element is expanding or contracting.
 * scrollOut() is called by onclick from either div.compHead (child of div.comp)
 *
 * @param scrollTrigger is the element that the call came from
 * @param compId is the id of the element that will be scrolled
 */
var scrollOutPeriod = 5;	//used in scrollOutTimed(); defines period
var scrollOutSteps = 1;		//used in scrollOut() and scrollOutTimed(); defines number of steps
function scrollOut(curObj, compId) {
	var content = document.getElementById(compId);
	var expFlagField = document.getElementById("expFlag" + compId);
	if (expFlagField === null) {
		var hiddenInput = document.createElement("input");
		hiddenInput.type = "hidden";
		hiddenInput.setAttribute("id", "expFlag" + compId);
		content.appendChild(hiddenInput);
		hiddenInput.setAttribute("value", "false");
		expFlagField = document.getElementById("expFlag" + compId);
	}

	try{
		document.scrollTr = document.getElementById(compId+'Img');
	}catch(err){
		window.alert(err);
	}

	/* remember original height of this component */
	if (!content.proposedHeight) {
		content.proposedHeight = content.offsetHeight;
	}
	scrollOutTimed(scrollOutSteps, expFlagField.value == "true" ? true : false, compId); //do actual scrolling
}
/* Function scrollOutTimed() scrolls components in/out of view.
 * Calls itself with delay of scrollOutPeriod, scrollOutSteps times.
 *
 * @param stepsLeft how many steps left
 * @param expanding whether expanding or contracting
 * @param compId id of the component that we currently work
 */
function scrollOutTimed(stepsLeft, expanding, compId) {
	var content = document.getElementById(compId);
	var fraction = stepsLeft / scrollOutSteps; //fraction of visible component this "iteration"

	//when expanding....
	if (expanding) {
		fraction = 1 - fraction; //...fraction is reverse of that when contracting
	}
	//+1 to safeguard against a case where new height is 0 (visually 1px won't make a difference)
	var newHeight = fraction * content.proposedHeight + 1;
	content.style.height = newHeight + "px";
	if (stepsLeft != 0) {
		setTimeout("scrollOutTimed(" + (stepsLeft - 1) + ", " + expanding + ", '" + compId + "')", scrollOutPeriod / scrollOutSteps);
	} else {
		var btn = document.scrollTr;
		if (btn) { //do this only if button is there at all
		}
		btn.className = expanding ? "compClose" : "compOpen";
		if (expanding == false) {
			document.getElementById("expFlag" + compId).value = "true";
		} else {
			document.getElementById("expFlag" + compId).value = "false";
		}
	}
}

