var jsToolTip = {
	private:{
		main:null,
		top:null,
		content:null,
		bottom:null,
		test:true,
		attachedElements:new Array(),
		newElement:function(tagName,id,className,parentNode){
			var node = document.createElement(tagName);
			if(id)node.id=id;
			if(className)node.className=className;
			if(parentNode)parentNode.appendChild(node);
			return node;
		},
		findPos:function(obj){
			var curleft=curtop=0;
			if(obj.offsetParent){
				curleft=obj.offsetLeft;
				curtop=obj.offsetTop;
				while(obj=obj.offsetParent){
					curleft+=obj.offsetLeft;
					curtop+=obj.offsetTop;
				}
			};
			return [curleft,curtop];
		},
		show:function(innerHTML,pleft,ptop){
			this.main.className='';
			if(innerHTML){
				var match=innerHTML.match(/^[\d\D]{1,}\|/);
				if(/^[\d\D]{1,}\|/.test(innerHTML)){
					innerHTML = innerHTML.replace(match[0],'<div class="TTheader">'+match[0].replace(/\|$/,'</div>'));
				};
				this.content.innerHTML=innerHTML;
			};
			if(pleft){
				this.main.style.left=pleft+'px';
			};
			if(ptop){
				this.main.style.top=(ptop-this.main.clientHeight)+'px';
			};
			if(document.body.clientWidth-(this.findPos(this.main)[0]+this.main.clientWidth)<0){
				this.main.className='TTleft';
			};
			this.main.style.visibility='visible';
		},
		hide:function(){
			this.main.style.visibility='hidden';
		}
	},
	start:function(){
		this.private.main=this.private.newElement('div','ToolTip','TT3',document.body);
		this.private.top=this.private.newElement('div',null,'TTtop',this.private.main);
		this.private.content=this.private.newElement('div',null,'TTcontent',this.private.main);
		this.private.bottom=this.private.newElement('div',null,'TTbottom',this.private.main);
		this.private.main.style.visibility='hidden';
		this.private.main.style.position='absolute';
		this.private.main.style.left=
		this.private.main.style.top='0px';
		this.private.main.style.overflow=
		this.private.top.style.overflow=
		this.private.content.style.overflow=
		this.private.bottom.style.overflow='hidden';
		this.private.content.innerHTML='&nbsp;'
		this.private.content.onselectstart=
		this.private.content.onmousedown=function(){return false;};
		this.private.main.onmouseover=function(){this.private.show();return false;};
		this.private.main.onmouseout=this.private.main.onclick = function(){this.private.hide();return false;}
		this.private.main.private=this.private;
		this.attach();
	},
	attach:function(){
		this.detach();
		var imagelist=document.getElementsByTagName('*');
		for (var a=0;a<imagelist.length;a++){
			if((/(^|\s){1,}tooltip($|\s){1,}/i).test(imagelist[a].className)&&!(imagelist[a].title==''||typeof(imagelist[a].title)=='undefined')){
				this.private.attachedElements[this.private.attachedElements.length]=imagelist[a];
				imagelist[a].jsToolTip=this;
				imagelist[a].TThelp=imagelist[a].title;
				imagelist[a].title='';
				imagelist[a].onmouseover=function(){
					var myPosition=this.jsToolTip.private.findPos(this);
					this.jsToolTip.private.show(this.TThelp,myPosition[0],myPosition[1]);
					return false;
				};
				imagelist[a].onmouseout=function(){
					this.jsToolTip.private.hide();
					return false;
				};
				imagelist[a].onclick=function(){
					if(this.jsToolTip.private.main.style.visibility=='hidden'){
						var myPosition=this.jsToolTip.private.findPos(this);
						this.jsToolTip.private.show(this.TThelp,myPosition[0],myPosition[1]);
					}else{
						this.jsToolTip.private.hide();
					};
					return false;
				}
			}
		}
	},
	detach:function(){
		for(var a=0;a<this.private.attachedElements.length;a++){
			this.private.attachedElements[a].onmouseout=
			this.private.attachedElements[a].onmouseover=
			this.private.attachedElements[a].onclick=null;
			this.private.attachedElements[a].title=this.private.attachedElements[a].TThelp;
			this.private.attachedElements[a].TThelp='';
		};
		this.private.attachedElements=new Array();
	},
	init:function(){
		var This=this;
		if(typeof(window.addEventListener)!='undefined'){
			window.addEventListener('load',function(){This.start();},false);
		}else if(typeof(document.addEventListener)!='undefined'){
			document.addEventListener('load',function(){This.start();},false);
		}else if(typeof(window.attachEvent)!='undefined'){
			window.attachEvent('onload', function(){This.start()});
		}
	}
};jsToolTip.init();

