function initTooltips(config) {
	var tts = YAHOO.util.Dom.getElementsByClassName('tooltip', 'div');
	for (var i = 0; i < tts.length; i++) {
		new Tooltip(tts[i], config);
	}
}
function Tooltip(node, config) {
	this.DOMElement = node;
	this.ARROW_CORRECTION = 7;	
	this.config = config;
	
	this.vertical = YAHOO.util.Dom.hasClass(this.DOMElement, 'vertical') ? true : false;
	this.arrow = document.createElement('img');
	if (this.vertical) {
		this.arrow.id = 'tt-arrow-top';
		this.arrow.src = this.config.arrowTopSrc;
	} else {
		this.arrow.id = 'tt-arrow-right';
		this.arrow.src = this.config.arrowRightSrc;
	}
	this.DOMElement.appendChild(this.arrow);
	this.trigger = YAHOO.util.Dom.get(this.DOMElement.id + '-trigger');
	YAHOO.util.Event.addListener(this.trigger, 'mouseover', this.showTooltip, this, true);
	YAHOO.util.Event.addListener(this.trigger, 'mouseout', this.hideTooltip, this, true);
	YAHOO.util.Event.addListener(this.DOMElement, 'mouseover', this.keepShowing, this, true);
	YAHOO.util.Event.addListener(this.DOMElement, 'mouseout', this.hideTooltip, this, true);
}
Tooltip.prototype.showTooltip = function(e) {
	if (!e) var e = window.event;
	if (e.pageX ) {
		this.eventX = e.pageX;
	} else if (e.clientX) {
		this.eventX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	}
	this.showing = setTimeout(createContextFunction(this, "show"), 250);
}
Tooltip.prototype.show = function() {
	clearTimeout(this.showing);
	this.showing = -1;
	this.DOMElement.style.display = 'block';
	if (this.vertical) {
		this.x = YAHOO.util.Dom.getX(this.trigger) - (this.DOMElement.offsetWidth / 2) + 20;
		this.y = YAHOO.util.Dom.getY(this.trigger) + this.trigger.offsetHeight + 2;
	} else {
		this.x = YAHOO.util.Dom.getX(this.trigger) - this.DOMElement.offsetWidth - 5;
		this.y = YAHOO.util.Dom.getY(this.trigger) - (this.DOMElement.offsetHeight / 2) + this.ARROW_CORRECTION;
		if (this.x < 0) {
			this.x = this.eventX + 30;
			this.arrow.id = 'tt-arrow-left';
			this.arrow.src = this.config.arrowLeftSrc;
		} else {
			this.arrow.id = 'tt-arrow-right';
			this.arrow.src = this.config.arrowRightSrc;
		}
		this.arrow.style.top = (this.DOMElement.offsetHeight / 2) - this.ARROW_CORRECTION + "px";
	}
	YAHOO.util.Dom.setXY(this.DOMElement, [this.x, this.y]);
}
Tooltip.prototype.keepShowing = function() {
	clearTimeout(this.hiding);
	this.hiding = -1;
}
Tooltip.prototype.hideTooltip = function() {
	clearTimeout(this.showing);
	this.showing = -1;
	this.hiding = setTimeout(createContextFunction(this, "hide"), 150);
}
Tooltip.prototype.hide = function() {
	clearTimeout(this.hiding);
	this.hiding = -1;
	this.DOMElement.style.display = 'none';
}
