//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com | http://solardreamstudios.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//
// Imporeved by Frank Naegler
// http://www.frank-naegler.de
//////////////////////////////////////////////////////////////////

var Tooltip = {
	Version: '1.4',
	init: function(eles) {
		this.eles = eles;
		this.offsetX = (arguments[1])?(arguments[1]):(-30);
		this.offsetY = (arguments[2])?(arguments[2]):(25);

		this.tipNameSpaceURI = 'http://www.w3.org/1999/xhtml';
		this.tipContainerID = 'qTip';
		this.tipContainer = document.getElementById(this.tipContainerID);
		if(!this.tipContainer) {
	  		this.tipContainer = document.createElementNS ? document.createElementNS(this.tipNameSpaceURI, 'div') : document.createElement('div');
			this.tipContainer.setAttribute('id', this.tipContainerID);
	  		document.getElementsByTagName('body').item(0).appendChild(this.tipContainer);
		}
		if (!document.getElementById) return;
		
		this.tip = document.getElementById(this.tipContainerID);
		if (this.tip) document.onmousemove = Tooltip.move.bindAsEventListener(this);

		var a, sTitle;
		this.allElements = new Array();
		for (var i=0;i<this.eles.length;i++) {
			var eList = document.getElementsByTagName(this.eles[i]);
			for (var j=0;j<eList.length;j++)
				this.allElements.push(eList[j]);
		}

		for (var i = 0; i < this.allElements.length; i ++) {
			e = this.allElements[i];
			sTitle = e.getAttribute('title');
			sAlt   = e.getAttribute('alt');
			sClass = e.getAttribute('class');
			sClass = sClass ? sClass : e.getAttribute("className");

			if(sTitle && (sClass != 'noTooltip')) {
				e.removeAttribute('title');
				if (sAlt) e.removeAttribute('alt');
				e.onmouseover = Tooltip.show.bind(this, sTitle);
				e.onmouseout = Tooltip.hide.bind(this);
			}
		}
	},
	move: function (evt) {
		var x=0, y=0;
		if (document.all) {//IE
			x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
			y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			x += window.event.clientX;
			y += window.event.clientY;
		} else {//Good Browsers
			x = evt.pageX;
			y = evt.pageY;
		}
		this.tip.style.left = (x + this.offsetX) + 'px';
		this.tip.style.top = (y + this.offsetY) + 'px';
	},
	show: function (text) {
		if (!this.tip) return;
		this.tip.innerHTML = text;
		Element.show(this.tip);
		this.tip.style.display = 'block';
	},
	hide: function () {
		if (!this.tip) return;
		this.tip.innerHTML = '';
		this.tip.style.display = 'none';
	}
}
function initTooltip() {
	Tooltip.init(['a'], -20, -40);
}
addEvent(window, 'load', initTooltip);
