var toolTipStartTime = 1000;
var timeOut = 0;
var tooltipMsg = "";
var positionCall = false; // it enables the position method only tooltip show() started.
var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt = document.getElementById("tt");
	var t = document.getElementById("tttop");
	var c = document.getElementById("ttcont");
	var b = document.getElementById("ttbot");
	var h;
	var ie = document.all ? true : false;
	var u=0;
	var l=0;
	return{
		show:function(){
				tt = document.getElementById("tt");
				t = document.getElementById("tttop");
				c = document.getElementById("ttcont");
				b = document.getElementById("ttbot");
				if(tt != null){
					tt.style.opacity = 0;
					tt.style.filter = 'alpha(opacity=0)';
					tt.style.display = 'block';
					c.innerHTML = tooltipMsg;
					tt.style.width = 'auto';
					if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
					h = parseInt(tt.offsetHeight) + top;
					tt.style.top = (u - h) + 'px';
					tt.style.left = (l + left) + 'px';
					clearInterval(tt.timer);
					tt.timer = setInterval(function(){tooltip.fade(1)},timer);
				}
				
		},
		pos:function(e){
			if(positionCall){
				if( !ie ){
					u = e.pageY;
					l = e.pageX;
				}else{
					if( document.documentElement.scrollTop ){
						u = event.clientY + document.documentElement.scrollTop;
						l = event.clientX + document.documentElement.scrollLeft;
					}else{
						u = event.clientY + document.body.scrollTop;
						l = event.clientX + document.body.scrollLeft;
					}
				}
				if(tt != null){
					tt.style.top = (u - h) + 'px';
					tt.style.left = (l + left) + 'px';
				}
			}
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){
					tt.style.display = 'none';
				}
			}
		},
		hide:function(){
				clearTimeout(timeOut);
				if(tt != null && tt != null && tt.timer != null && tt.timer != 'undefined'){
					clearInterval(tt.timer);
					tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
				}
		}
	};
}();
document.onmousemove = tooltip.pos;

function showToolTip(msg){
	tooltipMsg = msg;
	positionCall = true;
	timeOut = setTimeout("tooltip.show()",toolTipStartTime);
}
