/*
 * MappaTo JavaScript Library v1.0.0
 * http://www.comune.torino.it/
 * Copyright (c) 2009 Comune di Torino
 * Module licensed under GNU Affero GPL licenses.
 * http://www.gnu.org/licenses/agpl.html
 * Date: 2009
 */
function Fade(){
	this.speed = 10;
	this.timer = 20;
	this.endalpha = 95;
	this.alpha = 0;
	this.obj;
	this.ie = document.all ? true : false;
	this.runFade = function(d){
			var a = this.alpha;
			if((a != this.endalpha && d == 1) || (a != 0 && d == -1)){
				var i = this.speed;
				if(this.endalpha - a < this.speed && d == 1){
					i = this.endalpha - a;
				}else if(this.alpha < this.speed && d == -1){
					i = a;
				}
				this.alpha = a + (i * d);
				this.obj.style.opacity = this.alpha * .01;
				this.obj.style.filter = 'alpha(opacity=' + this.alpha + ')';
				//objLibs.printMsgBox('fade - ' + this.alpha + '');
			}else{
				clearInterval(this.obj.timer);
				if(d == -1){this.obj.style.display = 'none'}
				//objLibs.printMsgBox("fade - none");
			}
		};
	this.runFadeIn = function(obj){
		this.obj = obj;
		this.alpha = 0;
		this.obj.style.opacity = this.alpha;
		this.obj.style.filter = 'alpha(opacity='+this.alpha+')';
		this.obj.style.display = "block";
		clearInterval(this.obj.timer);
		//objLibs.printMsgBox('runFadeIn - ' + this.alpha + '');
		this.obj.timer = setInterval(function(){objFade.runFade(1)},this.timer);
	};
	this.runFadeOut = function(obj){
		this.obj = obj;
		clearInterval(this.obj.timer);
		//objLibs.printMsgBox('runFadeOut');
		this.obj.timer = setInterval(function(){objFade.runFade(-1)},this.timer);
		//this.obj.style.display = 'none';
	};
};

/* Initialize Fade sigleton */
function initFade()
{
	if (typeof oldOnLoadFade == 'function') oldOnLoadFade();
	objFade = new Fade();
}

/* Var sigleton instance*/
var objFade;

/* Event initialize */
var oldOnLoadFade;
if (typeof window.onload == 'function') 
	oldOnLoadFade = window.onload;
window.onload = initFade;
