TINY={};

function T$$$(){return document.all?1:0}

TINY.tooltip=function(){
	var b,h,w,a,v,p=0;
	return{
		show:function(o){
			v={opacity:100,fade:1,autohide:0,width:0,id:0,height:0,position:'dynamic',iframe:0,html:0,url:0};
			for(s in o){v[s]=o[s]}
			if(!p){
				p=document.createElement('div'); p.className='tt';
				b=document.createElement('div'); b.className='ttcontent';
				a=document.createElement('div'); a.className='ttarrow';
				p.appendChild(b); p.appendChild(a); document.body.appendChild(p);
				p.func=new Function('event','TINY.tooltip.pos(event)')
			}else{
				clearTimeout(p.ah)
			}
			p.id=v.id;
			if(v.html&&!v.fade){
				p.style.opacity=v.opacity/100; p.style.filter='alpha(opacity='+v.opacity+')';
				p.style.width=v.width?v.width+'px':'auto'; p.style.height=v.height?v.height+'px':'auto';
				p.style.backgroundImage='none'; b.innerHTML=v.html; b.style.display=''
			}else{
				this.alpha(p,1,v.opacity)
			}
			if(v.autohide){p.ah=setTimeout(TINY.tooltip.hide,1000*v.autohide)}
			T$$$()?document.attachEvent('onmousemove',p.func):document.addEventListener('mousemove',p.func,1)
		},
		pos:function(e){
			var u=this.top(e), l=this.left(e), d=v.width/2;
			if(p-l+10<d){l=p-d-10}
			p.style.top=(u-v.height)+'px'; p.style.left=(l-d)+'px'
		},
		hide:function(){
			if(!v.fade){
				p.style.opacity=0; p.style.filter='alpha(opacity=0)';
				p.style.backgroundImage=''; b.innerHTML=''; b.style.display='';
				p.style.top=p.style.left='-500px'
			}else{
				this.alpha(p,-1,0)
			}
			T$$$()?document.detachEvent('onmousemove',p.func):document.removeEventListener('mousemove',p.func,1)
		},
		fill:function(c,u,w,h){
			if(u){
				if(v.image){
					var i=new Image(); i.onload=function(){w=w||i.width; h=h||i.height; TINY.box.psh(i,a,w,h)}; i.src=v.image
				}else if(v.iframe){
					this.psh('<iframe src="'+v.iframe+'" width="'+v.width+'" frameborder="0" height="'+v.height+'"></iframe>',w,h)
				}else{
					var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
					x.onreadystatechange=function(){
						if(x.readyState==4&&x.status==200){p.style.backgroundImage=''; TINY.box.psh(x.responseText,w,h)}
					};
					x.open('GET',c,true); x.send(null)
				}
			}else{
				this.psh(c,w,h)
			}
		},
		psh:function(c,w,h){
			if(typeof c=='object'){b.appendChild(c)}else{b.innerHTML=c}
			var x=p.style.width, y=p.style.height;
			if(!w||!h){
				p.style.width=w?w+'px':''; p.style.height=h?h+'px':''; b.style.display='';
				if(!h){h=parseInt(b.offsetHeight)}
				if(!w){w=parseInt(b.offsetWidth)}
				b.style.display='none'
			}
			p.style.width=x; p.style.height=y;
			this.size(w,h)
		},
		size:function(w,h){
			p.style.backgroundImage='none';
			p.style.width=w+'px'; p.style.height=h+'px'; b.style.display='';
			if(v.openjs){v.openjs()}
		},
		alpha:function(e,d,a){
			clearInterval(e.ai);
			e.ai=setInterval(function(){TINY.tooltip.ta(e,a,d)},20)
		},
		ta:function(e,a,d){
			var o=Math.round(e.style.opacity*100); console.log(o);
			if(o==a){
				clearInterval(e.ai);
				if(d==-1){
					b.innerHTML=p.style.backgroundImage=''
				}else{
					if(v.opacity==100){p.style.filter=''}
					TINY.tooltip.fill(v.html||v.url,v.url||v.iframe||v.image,v.width,v.height)
				}
			}else{
				var n=a-Math.floor(Math.abs(a-o)*.5)*d;
				e.style.opacity=n/100; e.style.filter='alpha(opacity='+n+')'
			}
		},
		top:function(e){
			return T$$$()?window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop:e.clientY+window.scrollY
		},
		left:function(e){
			return T$$$()?window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft:e.clientX+window.scrollX
		}
	}
}();
