function tooltip(elem,text, width){
	var d = document;
	this.init = function(){
		if(typeof elem=="string")
			elem = d.getElementById(elem);
		this.e = elem;
		this.createTooltip();
		this.e.tooltip = this;

		this.addEvents(this.e);
		this.e.onmouseout = function(){elem.tooltip.hide();};
	};
	this.createTooltip = function(){
		this.div = d.createElement('div');
		this.div.className = "tooltip";
		this.div.style.display = "none";
		if(!isNaN(width)) this.div.style.maxWidth = width+'px';
		this.p = d.createElement('p');
		this.p.innerHTML = text;
		this.div.appendChild(this.p);
		d.body.appendChild(this.div);
		
		this.div.onclick = function(){elem.tooltip.hide();};
	};
	this.addEvents = function(el){
		//chist@ hetevial toghn a, ughghaki vor Slideri het EventBubbling linelu hamar pokhel em
		//el.onmousemove=function(e){elem.tooltip.show(e);};
		//araijm senc anem, minchev aveli xeloq ban kmtacem
		el.onmousemove=function(e){ if(this.f)this.f(e); elem.tooltip.show(e);};
		var arr = el.childNodes;
		for(var i=0;i<arr.length;i++)
			if(arr[i].nodeType==1) //element
				this.addEvents(arr[i]); //rekursia!
	};
	this.removeEvents = function(el){
		el.onmousemove = function(){return};
		var arr = el.childNodes;
		for(var i=0;i<arr.length;i++)
			if(arr[i].nodeType==1) //element
				this.removeEvents(arr[i]); //rekursia!
	};
		
	
	//Public function
	this.show = function(e){
		e = e ? e : window.event;
		if(this.div.style.display!="block")
			this.div.style.display="block";
		this.div.style.left = (e.clientX+6) + 'px';
		this.div.style.top  = (e.clientY+13) + 'px';
	};
	this.hide = function(){
		if(this.div.style.display!="none")
			this.div.style.display="none";
	};
	this.remove = function(){
		d.body.removeChild(this.div);
		this.removeEvents(this.e);
		this.e.tooltip = null;		
	};
	
	this.init();
}