/************************************************************
Globals
*************************************************************/

// Fade FX
var _FADE_INTERVAL_ID 	= null;		// ID of the fade interval process
var _FADE_DEGREE		= 0;		// Degree of fading to apply to the fadable element
var _FADE_STEP			= 0;		// Counter; what step of the fade process we are on
	
/************************************************************
FUNCTIONS
*************************************************************/

/************************************************************
Special FX
*************************************************************/
/*
*	Fade the object having the given ID, after the given initDelay,
*	at the specified intervalTime, starting with the initial degree of fade,
*	and increasing/decreasing by increment until reaching endDegree
*	Note: intervalDegree must divide evenly into (endDegree - initDegree).
*		shrink			string; one of ("vertical", "horizontal") - whether or not to shrink the object down to nothing
*		stepToShrink	integer; step of the fade process at which to begin the shrinking
*/
function fadeObject(id,initDelay,intervalTime,initDegree,intervalDegree,endDegree,shrink,stepToShrink) {
	setTimeout(function() { startFadeOut(id,intervalTime,initDegree,intervalDegree,endDegree,shrink,stepToShrink);},initDelay);
}

/*
*	Start the Fading interval process
*/
function startFadeOut(id,intervalTime,initDegree,intervalDegree,endDegree,shrink,stepToShrink) {
	// initialize degree counter
	_FADE_DEGREE	= initDegree;
	_FADE_STEP = 0;
	
	// Define function to be called on interval
	var intervalFunc = function(id,intervalDegree,endDegree,shrink,stepToShrink) {
		var obj = document.getElementById(id);
		
		// if still visible, keep fading
		if (obj && _FADE_DEGREE != endDegree){
			_FADE_DEGREE	+= intervalDegree;
			setOpacity(obj,_FADE_DEGREE);
			_FADE_STEP++;
			
		// otherwise, cancel the interval process
		} else{
			clearInterval(_FADE_INTERVAL_ID);
			
			// if shrink was set, make sure object is removed entirely
			if (shrink=="vertical" || shrink=="horizontal") {
				obj.style.display = "none";
			}
		}
	};
	
	// start the interval process
	_FADE_INTERVAL_ID = setInterval(function() {intervalFunc(id,intervalDegree,endDegree,shrink,stepToShrink);},intervalTime);
}
	
/************************************************************
Utilities
*************************************************************/
function setOpacity (obj,deg) {
	if (typeof(obj.filters)=="object" && typeof(obj.filters[0])=="object") {
		if (typeof(obj.filters[0].opacity) == "number") {	// if IE6+
			obj.filters[0].opacity = deg;
		} else { 	// else if IE5.5-
			obj.style.filter = "alpha(opacity=" + deg + ")";
		}
	} else if (typeof(obj.style.MozOpacity) == "string") {
		obj.style.MozOpacity = "" + deg/101 + "";
	} else if (typeof(obj.style.KhtmlOpacity) == "string") {
		obj.style.KhtmlOpacity = "" + deg/101 + "";
	} else if (obj.style.opacity && !obj.filters) {
		obj.style.opacity = deg/101;
	}
}
