function CTooltip() {}

CTooltip.prototype = {
	element:null, 
	html:null, 
	className:null, 
	width:null, 
	height:null, 

	onshow:null, 

	_div:null, 

	init:function(element, html, className, width, height)
	{      
		this.element = element;
		this.html = typeof html == 'string' ? html : html.innerHTML;
		this.className = className;
		this.width = width ? width : '250px';
		this.height = height ? height : 'auto';

		this._div = document.createElement('div');
		this._div.className = this.className;
		this._div.innerHTML = this.html;

		this._div.style.visibility = 'hidden';
		this._div.style.position = 'absolute';
		this._div.style.overflow = 'hidden';
		
                document.getElementsByTagName('body')[0].appendChild(this._div);
		this._div.style.width = this.width;
		//this._div.style.height = this.height;
		this._div.style.height = '1px';

		var _this = this;
		this.element.onmousemove = function(e) { _this._onmousemove(e?e:event); }
		this.element.onmouseout = function(e) { _this._onmouseout(e?e:event); }	
		if (this.onshow)
			this.element.onmouseover = function() { _this.onshow(_this); }
                        
	}, 

	setHtml:function(html) {
		this.html = html;
		this._div.innerHTML = html;	
	}, 

	_onmousemove:function(e) {
		var xy = getEventWindowXY(e);
		var sx = 10 ; var sy = 10;
		var w = this._div.offsetWidth;
		var h = this._div.offsetHeight;
		var winW = window.innerWidth ? window.innerWidth : document.body.offsetWidth;
		var winH = window.innerHeight ? window.innerHeight : document.body.offsetHeight;
		var sl = document.body.scrollLeft;
		var st = document.body.scrollTop;
/*		window.status = winW;*/
		if (xy.x + sx + w < winW - 24)
			xy.x = xy.x + sx + sl;
		else
			xy.x = xy.x - sx - w + sl;
		
		if (xy.y + sy + h < winH - 24)
			xy.y = xy.y + sy + st;
	        else
	        	xy.y = xy.y - sy - h + st;

	        this._div.style.left = xy.x + 'px';
	        this._div.style.top = xy.y + 'px';
		
		this._div.style.visibility = 'visible';		
		this._div.style.height = this.height;
	}, 

	_onmouseout:function(e) {
		this._div.style.visibility = 'hidden';
	}
}