// JavaScript Document

/* FadeIn / FadeOut Script */

// fadein time in ms
var fadetime = 200;
// Number of steps
var steps = 100;
var maxopacity = 90;
var fadedIn = null;

var state_A = false;
var state_B = false;

function inA(currentObject) {
	state_A = true;
	if (fadedIn == null) {
		fadedIn = currentObject;
		fadeIn(currentObject);
	}
}

function outA(currentObject) {
	state_A = false;
	window.setTimeout("testFadeOut()", 10);
}

function inB(currentObject) {
	state_B = true;
}

function outB(currentObject) {
	state_B = false;
	window.setTimeout("testFadeOut()", 10);
}

function testFadeOut() {
	if (!(state_A || state_B)) {
		fadeOut(fadedIn);
	}
}

function fadeIn(currentObject) {
	fadedIn = currentObject;
	currentObject = currentObject.firstChild;
	while (currentObject.nodeType != 2 && currentObject.nodeName != "UL") {
		currentObject = currentObject.nextSibling;
	}
	fadeInObject = currentObject;
	currentObject.style.display = "block";
	setOpacity(0);
	for (var i = 1; i <= steps; i++) {
		window.setTimeout("setOpacity(" + maxopacity * i / steps + ")", Math.round(i * fadetime / steps));
	}
}

function fadeOut(currentObject) {
	currentObject = currentObject.firstChild;
	while (currentObject.nodeType != 2 && currentObject.nodeName != "UL") {
		currentObject = currentObject.nextSibling;
	}
	fadeInObject = currentObject;
	setOpacity(0);
	currentObject.style.display = "block";
	for (var i = 1; i <= steps; i++) {
		window.setTimeout("setOpacity(" + maxopacity * (steps - i) / steps + ")", Math.round(i * fadetime / steps));
	}
	setTimeout(function() { fadedIn = null; currentObject.style.display = "none"; state = 0;}, fadetime);
}

function setOpacity(opacity) {
	currentObject = fadeInObject;
	currentObject.style.opacity = (opacity / 100); 
	currentObject.style.MozOpacity = (opacity / 100); 
	currentObject.style.KhtmlOpacity = (opacity / 100); 
	currentObject.style.filter = "alpha(opacity=" + opacity + ")";
}
