function $FX_fade(){
	this.elements = new Array();
	this.TO_handlers = new Array();
}

$FX_fade.prototype.useElement = function(el){
	el = (typeof(el)=='object') ? el : document.getElementById(el);
	if(in_array(el, this.elements)){
		elkey = array_search(el, this.elements);

		//clear timeout
		clearTimeout(this.TO_handlers[elkey]);

		return elkey;
	}
	else{
		elkey = this.elements.length;
		this.elements[elkey] = el;
		return elkey;
	}
}

$FX_fade.prototype.fadeout = function(el, step, timeout, limit, afterFunction){
	var elkey = this.useElement(el);
	el = this.elements[elkey];

	var cO = (el.style.opacity) ? el.style.opacity : 1; //current opacity

	//validate step and timeout

	//default step and timeout
	if(!step) step = 0.1;
	if(!timeout) timeout = 20;
	if(!limit) limit = 0;
	this.fadeout_1(elkey, step, timeout, limit, cO, afterFunction);
}

$FX_fade.prototype.fadeout_1 = function(elkey, step, timeout, limit, cO, afterFunction){
	if(cO>limit){
		cO = cO-step;
		if(cO<limit) cO = limit;
		my_setOpacity(this.elements[elkey], cO);
		var F = my_proxy(this.fadeout_1, this, false, elkey, step, timeout, limit, cO, afterFunction);
		this.TO_handlers[elkey] = setTimeout(F, timeout);
	}
	else{ //finished
		my_setOpacity(this.elements[elkey], limit);
		afterFunction();
	}
}

//fade in ////////////////////////////////
$FX_fade.prototype.fadein = function(el, step, timeout, limit, afterFunction){
	var elkey = this.useElement(el);
	el = this.elements[elkey];

	var cO = (el.style.opacity) ? el.style.opacity : 0; //current opacity

	//validate step and timeout

	//default step and timeout
	if(!step) step = 0.1;
	if(!timeout) timeout = 20;
	if(!limit) limit = 1;
	//alert(elkey, step, timeout, limit, parseFloat);
	this.fadein_1(elkey, step, timeout, limit, parseFloat(cO), afterFunction);
}

$FX_fade.prototype.fadein_1 = function(elkey, step, timeout, limit, cO, afterFunction){
	if(cO<limit){
		cO = cO+step;
		if(cO>limit) cO = limit;
		my_setOpacity(this.elements[elkey], cO);
		var F = my_proxy(this.fadein_1, this, false, elkey, step, timeout, limit, cO, afterFunction);
		this.TO_handlers[elkey] = setTimeout(F, timeout);
	}
	else{ //finished
		my_setOpacity(this.elements[elkey], limit);
		afterFunction();
	}
}
