
	function fading(element, handler)
	{
		this.element = element;
		this.handler = (handler == undefined) ? defaultFadingHandler : handler;
	}

	fading.prototype.element;
	fading.prototype.delay = 0;
	fading.prototype.value = 1;
	fading.prototype.speed = 0;
	fading.prototype.minValue = 0;
	fading.prototype.maxValue = 1;
	fading.prototype.timeoutId;

	fading.prototype.run = function()
	{
		if(this.delay)
		{
			if(this.timeoutId) clearTimeout(this.timeoutId);
			var fading = this;
			this.timeoutId = setTimeout(function(){fading.process();}, this.delay);
		}
		if(!this.timeoutId) this.process();		
	}
	
	fading.prototype.fade = function(speed)
	{
		this.speed = -speed;
		this.run();
	}

	fading.prototype.unfade = function(speed)
	{
		this.speed = speed;
		this.run();		
	}

	fading.prototype.process = function()
	{
		this.value += this.speed;
		this.timeoutId = undefined;

		if(this.speed > 0)
			if(this.value >= this.maxValue) 
			{
				this.value = this.maxValue;
				this.speed = 0;
			}

		if(this.speed < 0)
			if(this.value <= this.minValue)
			{
				this.value = this.minValue;
				this.speed = 0;
			}
		
		var fading = this;
		if(this.speed != 0) this.timeoutId = setTimeout(function(){fading.process();}, 10);
		
		this.handler(fading);
	}

	function defaultFadingHandler(fading)
	{
		var value = Math.round(Math.sin(fading.value * (3.14 / 2)) * 100) / 100;
		
/*		if(fading.element.filters)
		{
			//var filter = element.filters['DXImageTransform.Microsoft.Alpha'];
			//if(filter) filter.opacity = Math.round(value * 100);
			//else element.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+ Math.round(value * 100) + ")";
		}
		else
*/		
		{
		/*
			fading.element.style.opacity = value;
			fading.element.style.KhtmlOpacity = value;
			fading.element.style.MozOpacity = value;
		*/
		}
		
		fading.element.style.visibility = value == 0 ? 'hidden' : 'visible';

		//fading.element.style.position = 'relative';
		//fading.element.style.marginLeft = '-' + (fading.element.offsetWidth * (1 - value)) + 'px';
	}
