//////////////////////////////////////////////////////////////////
// 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
//////////////////////////////////////////////////////////////////

var qTipTag = new Array("img"); //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = 0; //This is qTip's X offset//
if (document.all)
{
    var qTipY = 20; //This is qTip's Y offset//
}
else
{
    var qTipY = -20; //This is qTip's Y offset//
}
var qTipXDisplayMode = "center";		// dyn = dynamisch ; abs = absolute ; static
var qTipYDisplayMode = "static";
var qTipPastWidth = 0;


//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null,
  disModeX : qTipXDisplayMode,
  disModeY : qTipYDisplayMode,pastWidth: qTipPastWidth}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle,anchors;
	
	for(var int_pos = 0;int_pos < qTipTag.length;int_pos++)
	{
		anchors = document.getElementsByTagName (qTipTag[int_pos]);
		
		for (var i = 0; i < anchors.length; i++) {
			a = anchors[i];
			sTitle = a.getAttribute("title");
			if(sTitle) {
				a.setAttribute("tiptitle" , sTitle);
				a.removeAttribute("title");
				a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
				a.onmouseout = function() {tooltip.hide()};
			}
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0,windowX=0,windowY=0;
	var TipSize=0,TipPos=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;
		windowX = (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
		windowY = (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
		windowX = evt.innerHeight;
		windowY = evt.innerWidth;
	}
	
	switch(this.disModeX)
	{
                case "center":
                        if( this.tip.offsetWidth > 0 ) {
                            this.tip.style.left = ( ( document.body.offsetWidth / 2 ) - (this.tip.offsetWidth / 2 ) ) + "px";
                            this.pastWidth = this.tip.offsetWidth;
                        } else {
                            this.tip.style.left = ( ( document.body.offsetWidth / 2 ) ) + "px";
//                            this.tip.style.left = ( ( document.body.offsetWidth / 2 ) - (this.tip.pastWidth / 2 ) ) + "px";
                        }
			
                break;
		case "dyn":
			TipSize = x+this.offsetX+250;
			if( windowX < TipSize )
			{
				TipPos =  x-this.offsetX-250;
			
				if(TipPos < 0)
					this.tip.style.left = 0;
					
				TipPos = TipPos + "px";
				this.tip.style.left = TipPos;
			}
			else
			{
				this.tip.style.left = (x + this.offsetX) + "px";
			}
			
		break;
		case "abs":
			if(this.tip.style.left != this.offsetX + "px")
			{
				this.tip.style.left  = this.offsetX + "px";
			}
		break;
		case "static":
		default:
			this.tip.style.left = (x + this.offsetX) + "px";
	}
	
	switch(this.disModeY)
	{
		case "dyn":
			TipSize = y+this.offsetY+500;
			
			var addY = -250;
			if ( y+160 < windowY )
			{
				addY = 0;
			}
			
			if( windowY < TipSize )
			{
				TipPos =  y-this.offsetY+addY;
				if(TipPos < 0)
					this.tip.style.top = 0;
					
				TipPos = TipPos + "px";
				this.tip.style.top = TipPos;
			}
			else
			{
				this.tip.style.left = (y + this.offsetY) + "px";
			}
		break;
		case "abs":
			if(this.tip.style.top != this.offsetY + "px")
			{
				this.tip.style.top  = this.offsetY + "px";
			}
		break;
		case "static":
		default:
			this.tip.style.top = (y + this.offsetY) + "px";
	}
	
	
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.style.display = "block";
	this.tip.innerHTML = text;
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function () {
	tooltip.init ();
}