function MxTdUtils () { // functions for Win IE 5+, Firefox and Safari 1+ (possibly work IE 5 Mac)

	var fadeStack = new Array(); // to fill with 'fade' objects, container of each fade fx parameters

	// to get window size, useful to place div @ center of screen
	this.getWindowSize = function() {
		var width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
		var height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
		var x = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
		var y = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);

		return {'width':width, 'height':height, 'x':x, 'y':y}
	}

	// to get a fade opacity effect on a element
	this.fadeLauncher = function(elmt, direction) {
		this.currentStep = 0;
		var fade = new Object();
		fade.direction = direction;
		//alert("fade.direction = "+fade.direction);
		fade.steps     = 10;
		fade.curStep   = 0;
		fade.id        = setInterval("mxtdutil.fadeElmt('"+elmt+"','"+fadeStack.length+"')", 40); // 40 msec = 25 fps
		fadeStack.push(fade);
	}

	this.fadeElmt = function(elmt, fsk) { // elmt : (string) element ID, fsk : (int) fadeStack array key
		fadeStack[fsk].curStep++;
		if (fadeStack[fsk].direction) { // fade from hidden to visible
			this.setOpacity(elmt, fadeStack[fsk].curStep * 10);
		} else { // fade from visible to hidden
			this.setOpacity(elmt, 100 - (fadeStack[fsk].curStep * 10));
		}
		if (fadeStack[fsk].curStep == fadeStack[fsk].steps) {
			//clearInterval(this.fadeID);
			if (fadeStack[fsk].direction == 0) {
				/* visible so it should be hidden */
				document.getElementById(elmt).style.visibility = "hidden";
			}
			clearInterval(fadeStack[fsk].id);
			fadeStack[fsk] = null;
		}
		
	}

	// set opacity of an element
	this.setOpacity = function(elmt, value) {
		var e = document.getElementById(elmt);
		if (navigator.userAgent.indexOf("Firefox") != -1) { // Firefox fix
			if (value == 100) { value = 99.9999; }
		}
		if ((navigator.userAgent.indexOf("MSIE") != -1) && (navigator.userAgent.indexOf("Mac") == -1)) { // Win IE
			e.style.filter = "alpha(opacity=" + value + ")";
		} else { // others like Firefox, Safari...
			e.style.opacity = (value / 100);
		}
	}

	// telephone popper : pop the number in a centered semi-transparent box (openly inspired by Apple Address Book "big font" command)
	this.telpopper = function(telnum) {
		var telpop = document.getElementById('telpop');	
		
		if (telpop.style.visibility == "visible") {
			/* fade to hidden */
			this.fadeLauncher('telpop', 0);
		} else {
			/* place it at right position */
			if (telpop.offsetWidth) {
				telpop.style.left = Math.round((this.getWindowSize().width / 2) - Math.round(telpop.offsetWidth / 2))+"px";
				telpop.style.top = Math.round((this.getWindowSize().height / 2) - Math.round(telpop.offsetHeight / 2))+"px";
			}
			
			/* fill the telephone number */
			telpop.innerHTML = ''; // IE 5.1 Mac fix
			telpop.innerHTML = telnum;
			
			/* make it visible capable */
			telpop.style.visibility = "visible";
			this.setOpacity('telpop', 0);
			
			/* fade to visible */
			this.fadeLauncher('telpop', 1);
		}
	}
}
mxtdutil = new MxTdUtils;
