function fade (_id) {

	// ********************
	// LOCAL VARIABLES
	var t = this;
	var iex = document.all;
	if(typeof _id == "object") var __element = _id;
	else var __element = document.getElementById(_id);	
	var __fadeTime;
	var __delay;
	var __timeLeft
	var __startTime;
	var __curTime;
	var __elapsedTime = 0;
	var __fadeDirection = 1;
	var __to;
	var __initMultiplier;
	t.onComplete = function(){};

	// ***************************************
	// PUBLIC FUNCTIONS	
	
	t.fadeOut = function(_seconds, _delay) {
		if(__element.style.opacity == 0 || __element.style.opacity == '') {
			if(iex) __element.style.filter = 'alpha(opacity = 100)';
			else __element.style.opacity = 1;
		}
		t.setTimes(_seconds, _delay);
		__initMultiplier = __element.style.opacity;
		__fadeDirection = -1;
		t.init();
	}
	
	t.fadeIn = function(_seconds, _delay) {
		if(__element.style.opacity == 1 || __element.style.opacity == '') {
			if(iex) __element.style.filter = 'alpha(opacity = 0)';
			else __element.style.opacity = 0;
		}
		t.setTimes(_seconds, _delay);
		__initMultiplier = 1 - __element.style.opacity;
		__fadeDirection = 1;
		t.init();
	}
	
	t.stop = function () {
		if(__to) clearTimeout(__to);
	}

	// ***************************************
	// PRIVATE FUNCTIONS	
	
	t.init = function () {
		t.stop();
		__startTime = null;
		__timeLeft = __fadeTime;
		timerComplete = function() { t.changeOpacity(); };
		__to = setTimeout(function() { t.changeOpacity(); }, __delay);
	}
	
	t.changeOpacity = function () {
		if(!__startTime) __startTime = new Date().getTime();
		__curTime = new Date().getTime();
		__elapsedTime = __curTime - __startTime;
		
		if(__fadeTime <= __elapsedTime) {
		  if(iex) __element.style.filter = 'alpha(opacity = ' + (__fadeDirection == 1 ? '100' : '0') + ')';
		  else __element.style.opacity = __fadeDirection == 1 ? '1' : '0';
		  if(t.onComplete) t.onComplete();
		  return;
		}
		
		__timeLeft = __fadeTime - __elapsedTime;
		var newOpVal = __initMultiplier * __timeLeft / __fadeTime;
		if(__fadeDirection == 1) newOpVal = 1 - newOpVal;
		
		if(iex) __element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
		else __element.style.opacity = newOpVal;
		
		__to = setTimeout(function() { t.changeOpacity(); }, 33);
	}
	
	t.setTimes = function(_seconds, _delay) {
		__fadeTime = (_seconds != null) ? (_seconds * 1000) : 300; 	// default 1 second
		__delay = (_delay != null) ? (_delay * 1000) : 0;			// default 3 seconds
	}
	
}