function CToolTip(config)
{
    with(CToolTip) {
        if (prototype.counter==undefined) prototype.counter = 1; else prototype.counter++;

        prototype.show = function (evt)
	{
	    this.tooltipel.fireEvent('tooltipshow', this);
            var obj = this.tooltipel.style;
            if (obj.display != '') { this.visible = true; obj.display = ''; }
	    if (evt) {
              obj.left = (parseInt(evt.page.x)+this.tooltipX) + 'px';
              obj.top = (parseInt(evt.page.y)+this.tooltipY) + 'px';
	    }
	    else {
              obj.left = (getAbsolutePosition(this.ownerel).x+this.tooltipX) + 'px';
              obj.top = (getAbsolutePosition(this.ownerel).y+this.tooltipY) + 'px';
	    }
	    if (this.autohide && this.autohidedelay > 0) {
		this.addEvent('timer', function (tt) { tt.hide(); } );
		this.tooltipel.fireEvent('timer', this, this.autohidedelay);
	    }
	};

        prototype.hide = function (evt)
	{
	    this.tooltipel.fireEvent('tooltiphide', this);
            var obj = this.tooltipel.style;
            obj.display = 'none';
	    this.visible = false;
	};

	prototype.destroy = function () {
	   this.hide();
	   this.tooltipel.destroy();
	};

	prototype.setContent = function(content) {
	   this.content;
	   this.tooltipel.set('html', content);
	};

	prototype.addEvent = function (type, fn) {
	    this.tooltipel.addEvent(type, fn);
	};
    }
    this.id = CToolTip.prototype.counter;
    this.content = config.content;
    this.owner = config.owner;
    this.ownerel = $(this.owner);
    this.tooltipel = new Element('div', {'id': 'tooltip'+this.id, 'class': (config.cls ? config.cls : 'tooltip'), 'html': this.content, 'styles': {'display': 'none'}});
    this.visible = false;
    if (config.autoshow!=undefined)
      this.autoshow = config.autoshow;
     else
      this.autoshow = true;
    if (config.autohide!=undefined)
      this.autohide = config.autohide;
     else
      this.autohide = false;
    if (config.autohidedelay!=undefined)
      this.autohidedelay = config.autohidedelay;
     else
      this.autohidedelay = 500;
    if (config.width) this.tooltipel.style.width = config.width+'px';
    if (config.height) this.tooltipel.style.height = config.height+'px';
    if (Browser.Engine.trident)
    {
       var objBody = document.getElementsByTagName("body").item(0);
       objBody.insertBefore(this.tooltipel, objBody.firstChild);
    }
    else {
      var objBody = $(document.body);
      objBody.grab(this.tooltipel, 'bottom');
    }
    this.tooltipX = (config.spaceX!=undefined ? config.spaceX: 15);
    this.tooltipY = (config.spaceY!=undefined ? config.spaceY: 15);

    if (this.ownerel)
    {
        this.ownerel.tooltipobj = this;
	if (this.autoshow)
	{
        this.ownerel.addEvent('mousemove', function (ev) {
               this.tooltipobj.show(ev);
            });
        this.ownerel.addEvent('mouseout', function (ev) {
               this.tooltipobj.hide(ev);
            });
	}
    }
}
