var sollBewegen = false;
var richtung = 'rechts';
var obenunten = 'unten';
var tt = null;

function showTTByID(id, bewegen, _richtung) {
	if (_richtung == null) {
		_richtung = 'rechts';
	}
	richtung = _richtung;
	document.onclick = mousepos;
	tt = document.getElementById(id);
	tt.style.display = "block";
	sollBewegen = bewegen;
}

function showTT(text, bewegen) {
	document.onclick = mousepos;
	
	tt = document.createElement('div');
	var divIdName = 'tmp_tt_0';
	tt.setAttribute('id', divIdName);
	tt.setAttribute('style', "display: none;font: 11px Verdana,Arial;");
	tt.setAttribute('class', "tooltip");
	tt.innerHTML = text;
	document.body.appendChild(tt);
	tt.style.display = "block";
	sollBewegen = bewegen;
}

function mousepos(e) {
	x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	if (tt != null) {
		if (sollBewegen) {
			dazu = 5;
		} else {
			dazu = 5 - (tt.style.width + 10);
		}
		if (richtung == 'links') {
			alert(tt.style.left);
			// tt.style.right = (x - dazu) + "px";
			tt.style.left = ((x - dazu) - tt.style.width) + "px";
			alert(tt.style.left);
		} else {
			tt.style.left = (x + dazu) + "px";
		}
		if (obenunten == 'oben') {
			// tt.style.bottom  = (y - dazu) + "px";
			tt.style.top = ((y - dazu) - tt.style.height) + "px";
		} else {
			tt.style.top  = (y + dazu) + "px";
		}
	}
	document.onclick = leer;
}

function leer() {
	// Tue nichts
}

document.onmousemove = updateTT;
 
function updateTT(e) {
	if (sollBewegen) {
		if (tt != null && tt.style.display == 'block') {
			x = (e.pageX ? e.pageX : window.event.x) + tt.offsetParent.scrollLeft - tt.offsetParent.offsetLeft;
			y = (e.pageY ? e.pageY : window.event.y) + tt.offsetParent.scrollTop - tt.offsetParent.offsetTop;
			if (sollBewegen) {
				dazu = 5;
			} else {
				dazu = 5 - (tt.style.width + 10);
				alert(dazu);
			}
			tt.style.left = (x + dazu) + "px";
			tt.style.top  = (y + dazu) + "px";
		}
	}
}

function hideTT(id) {
	if (id == null) {
		document.body.removeChild(tt);
	} else {
		document.getElementById(id).style.display = "none";
	}
}
