// 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 (outID, inID, func) {
		try {
			//alert("fading " + id);
			this.outOpacity = 100;
			this.inID = inID;
			this.inOpacity = 0;
			this.outID = outID;
			
			this.func = func;
			this.fadeLoop();
		}
		catch(e) {
			alert(e);	
		}
	}

	this.fadeLoop = function () {
		try {
			var self = this;
			var process = function() {
				try {				
					if (self.outOpacity - self.stepAmount > 0) {
						self.outOpacity -= self.stepAmount;
						self.setOutOpacity();
					}
					else {
						self.outOpacity = 0;
						self.setOutOpacity();
					}
					
					if(self.inOpacity + self.stepAmount < 100) {
						self.inOpacity += self.stepAmount;
						self.setInOpacity();
					}
					else {
						self.inOpacity = 100;
						self.setInOpacity();
					}
					
					//Do either fades need another iteration?
					if(self.inOpacity != 100 || self.outOpacity != 0) {
						window.setTimeout(process, self.stepTime);
					}
					else {
						self.func();
					}	
				}
				catch(e) {
					alert(e);	
				}
			}
			
			process();
		}
		catch(e) {
			alert(e);	
		}
	}

	this.setOutOpacity = function () {
		var o = document.getElementById(this.outID);
		
		o.style.filter = "alpha(opacity:" + this.outOpacity + ")";  	// IE
		o.style.KHTMLOpacity = this.outOpacity / 100;                 	// Konqueror
		o.style.MozOpacity = this.outOpacity / 100;                    // Mozilla (old)
		o.style.opacity = this.outOpacity / 100;                     	// Mozilla (new)
	}
	
	this.setInOpacity = function () {
		var o = document.getElementById(this.inID);
		
		o.style.filter = "alpha(opacity:" + this.inOpacity + ")";  	// IE
		o.style.KHTMLOpacity = this.inOpacity / 100;                 	// Konqueror
		o.style.MozOpacity = this.inOpacity / 100;                    // Mozilla (old)
		o.style.opacity = this.inOpacity / 100;                     	// Mozilla (new)
	}

}