// JavaScript Document
function Slowly (time, stepCount) {
	this.time = time;
	this.stepCount = stepCount;
	
	this.stepTime = (this.time/this.stepCount);
	this.stepAmount = (100/this.stepCount);
	if(this.stepAmount == 0) this.stepAmount = 1; //0 will cause infinite loop.

	
	this.fadeIn = function (id, func) {
		this.opacity = 0;
		this.id = id;
		this.func = func;
	
		this.fadeInLoop();
	}
	
	this.fadeInLoop = function()
	{
		var self = this;
		var process = function() {
			if (self.opacity + self.stepAmount < 100) {
						
						self.setOpacity(); 
	
						self.opacity += self.stepAmount;
	
						window.setTimeout(process, self.stepTime);
	
			} 
			else {
				self.opacity = 100;
				self.setOpacity();
				self.func();
			}
		}
		
		process();
	}

	this.fade = function (id, func) {
				//alert("fading " + id);
				this.opacity = 100;
 				this.id = id;
				this.func = func;
				this.fadeLoop();
	}

	this.fadeLoop = function () {
		var self = this;
		var process = function() {
				//alert("fadeLoop:  " + self.id+" "+self.opacity);
				
				if (self.opacity - self.stepAmount > 0) {

						self.setOpacity();

						self.opacity -= self.stepAmount;

						window.setTimeout(process, self.stepTime);

				} else {
						self.opacity = 0;
						self.setOpacity();
						self.func();
				}
		}
		
		process();
	}

	this.setOpacity = function () {
		//var debugDiv = document.getElementById("debug");
		
		var o = document.getElementById(this.id);
		//debugDiv.innerHTML = "Element:"+o+" Opacity:"+this.opacity;
		
		o.style.filter = "alpha(opacity:" + this.opacity + ")";  	// IE
		o.style.KHTMLOpacity = this.opacity / 100;                 	// Konqueror
		o.style.MozOpacity = this.opacity / 100;                    // Mozilla (old)
		o.style.opacity = this.opacity / 100;                     	// Mozilla (new)
	}

}