var TINY={};

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

TINY.tooltip=function(){
	var id='tt', o=3, t,m,a,x,h,p,d;
	return{
		show:function(o){
			if(t==null){
				t=document.createElement('div'); t.id=id;
				m=document.createElement('div'); m.id=id+'content';
				a=document.createElement('div'); a.id=id+'arrow';
				t.appendChild(m); t.appendChild(a); document.body.appendChild(t);
				t.p=new Function('event','TINY.tooltip.pos(event)')
			}
			var l=o.opacity||100; t.style.opacity=l/100; t.style.filter='alpha(opacity='+l+')';
			t.w=o.width; t.l=o.limit; if(o.class){t.className=o.class}
			T$$$()?document.attachEvent('onmousemove',t.p):document.addEventListener('mousemove',t.p,1);
			if(o.ajax){
				TINY.ajax.call(o.ajax.url,m.id,TINY.tooltip.display)
			}else{
				m.innerHTML=o.content; this.display()
			}
		},
		display:function(){
			t.style.display='block'; t.style.width='';
			x=t.offsetWidth; t.style.width=x>t.l?t.l+'px':t.w?t.w+'px':x+'px';
			h=parseInt(t.offsetHeight)+o; p=TINY.page.width()
		},
		pos:function(e){
			var u=TINY.cursor.top(e), l=TINY.cursor.left(e), d=x/2;
			if(p-l+10<d){l=p-d-10}
			t.style.top=(u-h)+'px'; t.style.left=(l-d)+'px'
		},
		hide:function(){
			t.style.display='none'; t.style.top=t.style.left='-1000px';
			T$$$()?document.detachEvent('onmousemove',t.p):document.removeEventListener('mousemove',t.p,1)
		}
	}
}();

TINY.ajax=function(){
  return{
    call:function(u,e,f,p){
      var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
      x.onreadystatechange=function(){
        if(x.readyState==4&&x.status==200){
          if(e){T$(e).innerHTML=x.responseText}
          if(f){
						if(typeof f!='function'){f=new Function(f)}
						f()
          }
        }
      };
      if(p){
        x.open('POST',u,true);
        x.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        x.send(p)
      }else{
        x.open('GET',u,true); x.send(null)
      }
    }
  };
}();

TINY.cursor=function(){
	return{
		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
		}
	}
}();


TINY.page=function(){
	return{
		width:function(){return self.innerWidth||document.documentElement.clientWidth},
		twidth:function(){
			var d=document, b=d.body, e=d.documentElement;
			return Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
		}
	}
}();
