/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com

Achtung: Diese Datei ist an die Besonderheiten von dejure.org angepaßt.
Wenn Sie diese Tooltip-Lösung übernehmen möchten, greifen Sie bitte auf
das Originalskript zurück: http://www.dustindiaz.com/sweet-titles/
*/
var sweetTitles = {
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['a', 'input'],	// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		if (document.getElementById('vorherigeVorschrift')) {
			document.getElementById('vorherigeVorschrift').alt = '';
		}
		if (document.getElementById('naechsteVorschrift')) {
			document.getElementById('naechsteVorschrift').alt = '';
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				if (current[j].href != "") {
					if (current[j].name != "" && this.tipElements[i] != 'input') {
						current[j].setAttribute('tip',gesetzesangaben(current[j].name));
					}
					else if (current[j].title != "") {
						current[j].setAttribute('tip',"<div class=\"tooltip_oben\">"+current[j].title+"</div>");
						current[j].removeAttribute('title');
					}
					else {
						continue
					}
					if (this.tipElements[i] == 'input') {
						addEvent(current[j],'click',this.tipOver);
						addEvent(current[j],'blur',this.tipOut);
					}
					else {
						addEvent(current[j],'mouseover',this.tipOver);
						addEvent(current[j],'mouseout',this.tipOut);
						addEvent(current[j],'click',this.tipOut);
					}
				}
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		sweetTitles.tip.style.visibility = 'hidden';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",500);
		sweetTitles.updateXY(e);
	},
	tipShow : function() {
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.checkNode();
		if (window.opera) {
			tp += 20
		}
		this.tip.innerHTML = anch.getAttribute('tip');
		einbl_breite = this.tip.offsetWidth
		einbl_hoehe = this.tip.offsetHeight
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(einbl_breite + lt) ) {
			this.tip.style.left = parseInt(lt-(einbl_breite + 15))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(einbl_hoehe+tp) ) {
			this.tip.style.top = parseInt(tp-(einbl_hoehe + 15))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '.1';
		this.tipFade(10);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+20);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else {
			this.tip.style.opacity = '1';
			this.tip.style.filter = "alpha(opacity:100)";
		}
	}
};

function umkehren(temp) {
	return temp
}

function gesetzesangaben(zeiger) {
	if (zeiger.match(/^bild:/)) {
		var bildangaben = zeiger.replace(/^bild:/, '').split('#')
		if (bildangaben.length == 4) {
			tip = '<div class="tooltip_oben"><img src="http://dejure.org/bilder/' + gb + '/' + bildangaben[0] + '" width="' + bildangaben[2] + '" heigth="' + bildangaben[3] + '">'
		}
		else {
			tip = '<div class="tooltip_oben"><img src="http://dejure.org/bilder/' + gb + '/' + bildangaben[0] + '">'
		}
		if (bildangaben[1] != '') {
			tip += '<div class="tooltip_unten">' + bildangaben[1] + '</div>'
		}
	}
	else {
		var a = zeiger.split(",")
		var tip = ''
		if (a.length != 1 && a[1] != 0) {
			tip = '<div class="tooltip_oben">'+pa[a[1]]+'</div>'
		}
		if (a.length == 3) {
			var gesetzbuch = '<b>'+gesetzschreibweise(a[2].replace(/'/g, ""))+'</b>'
		}
		else {
			var gesetzbuch = gesetzschreibweise(gb)
		}
		var gliederung = gl[a[0]].replace(/>/,"&gt;")
		tip += '<div class="tooltip_unten">'+gesetzbuch
		if (gliederung != '') {
			tip += ' &gt; '+gliederung
		}
		tip += '</div>'
	}
	return tip
}
function gesetzschreibweise(temp) {
	if (temp=="EuGVUE") temp="EuGVÜ"
	if (temp=="0BGB010901") temp="BGB (31.8.01)"
	if (temp=="0BGB010801") temp="BGB (31.7.01)"
	if (temp=="0BGB010102") temp="BGB (31.12.01)"
	if (temp=="0ZPO010102") temp="ZPO (31.12.01)"
	if (temp=="VOB-A") temp="VOB/A"
	if (temp=="VOB-B") temp="VOB/B"
	if (temp=="BoersG") temp="BörsG"
	if (temp=="LadOEG") temp="LadÖG"
	if (temp=="EWaermeG") temp="EWärmeG"
	if (temp=="EEWaermeG") temp="EEWärmeG"
	if (temp=="0VVG311207") temp="VVG a.F."
	if (temp=="0BNatSchG28022010") temp="BNatSchG a.F."
	if (temp=="0WHG28022010") temp="WHG a.F."
	if (temp=="AUEG") temp="AÜG"
	if (temp=="VStaettVO") temp="VStättVO"
	if (temp=="BauPruefVO") temp="BauPrüfVO"
	if (temp=="KrW-AbfG") temp="KrW-/AbfG"
	temp = temp.replace(/_$/, "")
	temp = temp.replace(/_/, " ")
	return temp
}
function pageLoader() {
	sweetTitles.init();
}
addEvent(window,'load',pageLoader);

