var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 90;
	var alpha = 0;
	var tt,c,h;
	var ie = document.all ? true : false;

	return{
		show:function(v,zzz,e,xxx){
			var l = 0; var u = 0;
			if (e.pageX) {
				l = e.pageX;
				u = e.pageY;
			} else if(e.clientX) {
				l = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
				u = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}

			left = 3; top = 6;

			if(tt == null){
				tt = document.createElement('div');
				tt.style.top = u + top + 'px';
				tt.style.left = l + left + 'px';
				tt.setAttribute('id',id);
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				tt.appendChild(c);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;

			var scrollX = (window.pageXOffset) ? window.pageXOffset : document.body.scrollLeft;
			var scrollY = (window.pageYOffset) ? window.pageYOffset : document.body.scrollTop;

			if((l+tt.offsetWidth+left+20) > (window.innerWidth+scrollX) ) { left = -1*tt.offsetWidth; }
			if((u+tt.offsetHeight+top+20) > (window.innerHeight+scrollY) ) { top = -1*tt.offsetHeight; }
			
			tt.style.top = u + top + 'px';
			tt.style.left = l + left + 'px';

			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		fixed:function(e){
		},
		pos:function(e){
			if(tt.style.display == 'none') return;
			var u = 500;
			var l = 0;
			if (!e) var e = window.event;
			if (e.pageX || e.pageY) {
				l = e.pageX;
				u = e.pageY;
			} else if(e.clientX || e.clientY) {
				l = e.clientX + document.body.scrollLeft
					+ document.documentElement.scrollLeft;
				u = e.clientY + document.body.scrollTop
					+ document.documentElement.scrollTop;
			}

			left = 3; top = 6;

			var scrollX = (window.pageXOffset) ? window.pageXOffset : document.body.scrollLeft;
			var scrollY = (window.pageYOffset) ? window.pageYOffset : document.body.scrollTop;

			if((l+tt.offsetWidth+left+20) > (window.innerWidth+scrollX) ) { left = -1*tt.offsetWidth; }
			if((u+tt.offsetHeight+top+20) > (window.innerHeight+scrollY) ) { top = -1*tt.offsetHeight; }

			tt.style.top = (u + top) + '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'}
				if(a==0) {
					document.onmousemove = this.pos;
					tips_disabled = 0;
				}
			}

		},
		hide:function(){
			if(tt) {
				clearInterval(tt.timer);
				tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
			}
		}
	};
}();