/* global.js */

var currFlydown = null;
var prevFlydown = null;
var currTimeId;
var prevTimeId;

/* functions for showing flydowns. only one can be open at a time.
	param: fName  -> number of div to open
	param: sec -> milloseconds before it should open
 */
function showFlydown(fName,sec) {

	if (currFlydown != null) {
		if (prevFlydown != null) {
			clearTimeout(prevTimeId);
			closeFlydown();
		}
		prevFlydown = currFlydown;	
	}
	currFlydown = fName;
	currTimeId = setTimeout('openFlydown()',sec);
}

function openFlydown() {
	var f = document.getElementById(currFlydown);
	f.style.display="block";
}

/* functions for hiding flydowns
	param: fName  -> name of div to close
	param: sec -> milloseconds before it should close
 */
function hideFlydown(fName,sec) {
	if (prevFlydown != null & prevFlydown != fName) {
		clearTimeout(prevTimeId);
		closeFlydown();
	}
	if (prevFlydown != fName); {
		prevFlydown = fName;
		prevTimeId = setTimeout('closeFlydown()',sec);
	}
}

function closeFlydown() {
	var f = document.getElementById(prevFlydown);
	f.style.display="none";
	prevFlydown = null;
}

/* stop the auto-close if user is hovering over open flydown */
function resetHide(fName) {
	if (prevFlydown == fName) {
		clearTimeout(prevTimeId);
		currFlydown = fName;
		prevFlydown = null;
	}
}

/* something was clicked. reset all the files */
function clearAll() {
	if (prevFlydown != null) {
		clearTimeout(prevTimeId);
		closeFlydown();
	}
	if (currFlydown != null) {
		clearTimeout(currTimeId);
		prevFlydown = currFlydown;
		closeFlydown();
	}
}
