/*
 * Sets the opacity of an element. Known to work with Firefox 2, Opera 9, IE 6
 * and 7, and Safari (Windows). IE requires that the element style has an
 * opacity filter, which can be initialised with the following property...
 *
 *     filter:alpha(opacity=100);
 *
 * Fails silently if techniques are unavailable.
 *
 * Parameters:
 *     el       the element to manipulate
 *     opacity  the desired opacity, from 0 to 1.
 */
function setOpacity(el, opacity) {
	if ('undefined' != typeof(el.style.opacity)) {
		el.style.opacity = opacity;
	} else if ('undefined' != typeof(el.style.MozOpacity)) {
		el.style.MozOpacity = opacity;
	} else if ('undefined' != typeof(el.filters) && 'undefined' != typeof(el.filters.alpha) && 'undefined' != typeof(el.filters.alpha.opacity)) {
		el.filters.alpha.opacity = opacity * 100;
	}
}

/*
 * Fades the specified element until its opacity counter (el._lt_fi_curr)
 * reaches or exceeds 1.
 *
 * Parameters:
 *     elid             the id of the element to manipulate
 *     el._lt_fi_delta  the increase in opacity for each cycle
 *     el._lt_fi_fps    the number of cycles per second
 *     el._lt_fi_post   the function to call upon completion
 */
function fadeIn(elid) {
	var el = document.getElementById(elid);

	// defaults
	if ('undefined' == typeof(el._lt_fi_delta)) {
		el._lt_fi_delta = 0.01;
	}
	if ('undefined' == typeof(el._lt_fi_fps)) {
		el._lt_fi_fps = 50;
	}
	if ('undefined' == typeof(el._lt_fi_curr) || el._lt_fi_curr >= 1) {
		el._lt_fi_curr = 0;
	}

	// fade
	el._lt_fi_curr += el._lt_fi_delta;
	setOpacity(el, el._lt_fi_curr);
	if (el._lt_fi_curr < 1) {
		window.setTimeout("fadeIn('" + elid + "')", 1000 / el._lt_fi_fps);
	} else if ('undefined' != typeof(el._lt_fi_post)) {
		el._lt_fi_post();
	}
}
