var toolTipLib = { 
	xCord : 0,
	yCord : 0,
	obj : null,
	tipElements : ['a','abbr','acronym'],
	attachToolTipBehavior: function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		addEvent(document,'mousemove',toolTipLib.updateXY,false);
		if ( document.captureEvents ) {
				document.captureEvents(Event.MOUSEMOVE);
		}
		for ( i=0;i<toolTipLib.tipElements.length;i++ ) {
			var current = document.getElementsByTagName(toolTipLib.tipElements[i]);
			var p = 0;
			for ( j=0;j<current.length;j++ ) {
				if (current[j].title && current[j].id!="top") {
				addEvent(current[j],'mouseover',toolTipLib.tipOver,false);
				addEvent(current[j],'mouseout',toolTipLib.tipOut,false);
				current[j].setAttribute('tip',current[j].title);
				current[j].setAttribute('pos',p);
				current[j].removeAttribute('title');
				p++;
				}
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			toolTipLib.xCord = e.pageX;
			toolTipLib.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			toolTipLib.xCord = window.event.clientX+document.documentElement.scrollLeft;
			toolTipLib.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function(e) {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		var l = getEventSrc(e);
		var div = document.getElementById('toolTip');
		if ( div ) {
			div.parentNode.removeChild(div);
		}
	},
	checkNode : function(obj) {
		var trueObj = obj;
		if ( trueObj.nodeName.toLowerCase() == 'a' || trueObj.nodeName.toLowerCase() == 'acronym' || trueObj.nodeName.toLowerCase() == 'abbr' ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		toolTipLib.obj = getEventSrc(e);
		tID = setTimeout("toolTipLib.tipShow()",500)
	},
	tipShow : function() {
		var wrapper = document.getElementById('gallery_projekte');
		var newDiv = document.createElement('div');
		var scrX = Number(toolTipLib.xCord);
		var scrY = Number(toolTipLib.yCord);
		var anch = toolTipLib.checkNode(toolTipLib.obj);
		var pos = anch.getAttribute('pos');
		var tp = parseInt(Math.floor(pos/4)*130);
		var lt = (parseInt(pos)%4+1)*120+(parseInt(pos)%4)*10;
		var pClass = "";
		if (lt > 380) { 
			pClass = ' class="right"';
			lt = 260;
		}
		
		/*if (anch.getAttribute('tip') == "Kunst- und Kommunika- tionszentrum Dettelbach") {
			pClass = ' class="right"';
			lt = 0;
			}*/
		/*if (anch.getAttribute('tip') == "Entdeckerruck- sack für Kinder im Orgel- baumuseum") {
			pClass = ' class="right"';
			lt = 130;
			}
		/*if (anch.getAttribute('tip') == "Die Rhön: Innenansichten einer Region") {
			lt = 130;
		}*/

		var addy = '';
		var access = '';
		newDiv.id = 'toolTip';
		wrapper.appendChild(newDiv);
		newDiv.style.opacity = '.1';
		tArray = anch.getAttribute('tip').split(':');
		tTxt = '<p'+pClass+'>'+tArray[0];
		if (tArray.length>1) { tTxt += " &ndash; <span> "+tArray[1]+"</span>"; } 
		tTxt += "</p>";
		newDiv.innerHTML = tTxt;
		newDiv.style.left = lt+'px';
		newDiv.style.top = tp+'px';
		toolTipLib.tipFade('toolTip',10);
	},
	tipFade: function(div,opac) {
		var obj = document.getElementById(div);
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 100 ) {
			obj.style.opacity = '.'+newOpac;
			obj.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = setTimeout("toolTipLib.tipFade('toolTip','"+newOpac+"')",30);
		}
		else { 
			obj.style.opacity = '1';
			obj.style.filter = "alpha(opacity:100)";
		}
	}
};
addEvent(window,'load',toolTipLib.attachToolTipBehavior,false);
