var tooltip=function(){
    var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 50;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,poupFlag,w){
			if(tt == null){
				tt = window.document.createElement('div');
				tt.setAttribute('id',id);
				tt.className = 'tt-main';
				t = window.document.createElement('div');
				t.setAttribute('id',id + 'top');
				t.className = 'tt-top';
				c = window.document.createElement('div');
				c.setAttribute('id',id + 'cont');
				c.className = 'tt-content';		
				b = window.document.createElement('div');
				b.setAttribute('id',id + 'bot');
				b.className = 'tt-bottom';
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				window.document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
			    if(!poupFlag)
				    window.document.onmousemove = this.pos;
			}
			
			if(poupFlag)
			{
			    tt.onmouseover = function(){tooltip.retainPos(true)};
                window.document.onmousedown = this.pos; 			
			}
			
			c.style.paddingTop = 2;
			tt.style.display = 'block';
	        var closeBtnHtml = "<div align='right' style='position:relative;'><img src='../Images/close.gif' title='close' class='image-button' onmousedown='tooltip.poupHide();'/></div>";
	        c.innerHTML = "";
			c.innerHTML = poupFlag ? (closeBtnHtml + v) : v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
		try{
			var u = ie ? event.clientY + window.document.body.scrollTop : e.pageY;
			var l = ie ? event.clientX + window.document.body.scrollLeft : e.pageX;
			tt.style.top = ((u - h) < 0 ? top:(u-h))+ 'px';
			tt.style.left = (l + left) + 'px';
			}catch(e){}
		},
		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(){
		    try{
		    clearInterval(tt.timer);
		    tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		    }
		    catch(e){}
		},
		poupHide:function(){
		    tt.style.display = 'none'
		},
		retainPos:function(e){
		    if(e)
		        window.document.onmousedown = "";
		    else
		       window.document.onmousedown = this.pos;	
		}
	};
}();

