/* ******************************************************************
	   TOOLTIPS 1.03 (c)2001-2002 Peter Kerl
	             www.peterkerl.de
                angepasst von Dietrich Borm
****************************************************************** */


// integriert: Crossbrowser-Funktionen von "cross.js"

// Config:
var ballonBack = "#00ff77";  // Hintergrundfarbe
var ballonText = "#000000";  // Text und Randfarbe
var ballonBreite = 200;        // Ballon-Breite (Vorgabewert)
var ballonBorder = 1;      // Randstärke
var ballonFont = "Arial";
var ballonDir = 0;         // Ausrichtung; 0=rechts 1=links, 2=Mitte
var ballonVDir = 0;        // Ausrichtung; 0=unten 1=oberhalb
var ballonChangeVDir = 220;    // Schwellwert für Wechsel der 
			      // V-Ausrichtung am unteren Rand
var ballonSpace = 10;        // Abstand vom Cursor
var ballonShow = false; // Anzeige aktiv/inaktiv

var Ballon = null;        // das DIV-Objekt
var b_Breite;             // aktueller Speicher für Ballonbreite
var b_Hoehe;
var b_Dir, b_VDir;

var RECHTS = 0;
var LINKS = 1;
var MITTE = 2;

// Ballon-Objekt (div) festlegen
function setBallon(id, breite, bgcolor) {
		
	document.onmousemove = cursorMove;
	
	if (breite && breite>20) b_Breite = breite;
	if (bgcolor) ballonBack = bgcolor;
	Ballon = crossGetObject(id);
	if (Ballon == null) {
		alert("keine Unterstützung für Ballon-Infos");
		showBallon = noBallon; hideBallon = noBallon;
	}
	ballonShow = false;
}
function noBallon() {} // functionsaufrufe abfangen
document.write('<meta name="scripts" content="TOOLTIPS 1.02 (c)2001-2002 Peter Kerl [www.peterkerl.de]">');

// Ballon kreieren und anzeigen
function showBallon1(msg, dir, breite, bgcolor) {
//	alert("showBallon1");
	var b_Back;
	var relWidth, relHeight;

	if (Ballon == null) return;

	// Wenn das erste Zeichen '%' ist, folgt die angenommene Höhe, gefolgt von einem weiteren '%'
	// => '%' einfach nur rausnehmen:
	if (msg.charAt(0) == '%') msg = msg.substr(1,msg.length-1);
	b_Zeilen = anzZeilen(msg);
//	alert("Anzahl Zeilen = " + b_Zeilen);
	b_Hoehe = b_Zeilen * 17 + 10;
//	alert("Ballonhöhe=" + b_Hoehe);
	if (breite && breite>20) b_Breite = breite;
	else b_Breite=ballonBreite;
	if (!dir) b_Dir = ballonDir;
	else b_Dir = dir;
	if (bgcolor) b_Back=bgcolor;
	else b_Back=ballonBack;
	msg = '<table width=' + b_Breite + ' border=0 cellpadding=' + ballonBorder + ' cellspacing=0 bgcolor=\"' + ballonText + '\"><tr><td><table width=100% border=0 cellpadding=3 cellspacing=0 bgcolor=\"' + b_Back + '\"><tr><td><font face=\"'  + ballonFont + '\" color=\"' + ballonText + '\" size=-1>' + msg + '</font></td></tr></table></td></tr></table>';
	relWidth = crossInnerWindowWidth() + crossGetScroll("x");
	relHeight = crossInnerWindowHeight() + crossGetScroll("y");
	if (b_Dir && b_Dir != 2) {
		if (crossMouseX + b_Breite + ballonSpace > relWidth) 
			{b_Dir = 1;}
		else if (crossMouseX < b_Breite + ballonSpace) b_Dir = 0;
	}
	b_VDir = ballonVDir;
//	alert("crossMouseY=" + crossMouseY + ", relHeight=" + relHeight);
	if (crossMouseY + b_Hoehe > relHeight) b_VDir = 1;
	else if (crossMouseY - ballonChangeVDir < 0) b_VDir = 0;
	crossWrite(Ballon, msg);
	ballonShow = true;
	crossShowObject(Ballon);
}

function showBallon2(msg, dir, breite, hoehe, bgcolor) {
//	alert("showBallon2");
//	alert("dir=" + dir + ", breite=" + breite + ", hoehe=" + hoehe + ", bgcolor=" + bgcolor);
	var b_Back;
	var relWidth, relHeight;

	if (Ballon == null) return;

	b_Hoehe = hoehe;
	if (breite && breite>20) b_Breite = breite;
	else b_Breite=ballonBreite;
	if (!dir) b_Dir = ballonDir;
	else b_Dir = dir;
	if (bgcolor) b_Back=bgcolor;
	else b_Back=ballonBack;
	msg = '<table width=' + b_Breite + ' border=0 cellpadding=' + ballonBorder + ' cellspacing=0 bgcolor=\"' + ballonText + '\"><tr><td><table width=100% border=0 cellpadding=3 cellspacing=0 bgcolor=\"' + b_Back + '\"><tr><td><font face=\"'  + ballonFont + '\" color=\"' + ballonText + '\" size=-1>' + msg + '</font></td></tr></table></td></tr></table>';
	if (!dir) b_Dir = ballonDir;
	else b_Dir = dir;
	relWidth = crossInnerWindowWidth() + crossGetScroll("x");
	relHeight = crossInnerWindowHeight() + crossGetScroll("y");
	if (b_Dir && b_Dir != 2) {
		if (crossMouseX + b_Breite + ballonSpace > relWidth) 
			{b_Dir = 1;}
		else if (crossMouseX < b_Breite + ballonSpace) b_Dir = 0;
	}
	b_VDir = ballonVDir;
	if (crossMouseY + b_Hoehe > relHeight) b_VDir = 1;
	else if (crossMouseY - ballonChangeVDir < 0) b_VDir = 0;
	crossWrite(Ballon, msg);
	ballonShow = true;
	crossShowObject(Ballon);
}

function showBallon(msg, dir, breite, hoehe, bgcolor) {
	if (bgcolor == null) showBallon1(msg, dir, breite, hoehe);
	else showBallon2(msg, dir, breite, hoehe, bgcolor);
}

function anzZeilen(text) {
	// Zeilen zählen:
	h_Zeilen = 1;
	h_msg = text;
	h_pos = posZeile(text);
	while (h_pos >= 0) {
		h_Zeilen++;
		h_msg = h_msg.substr(h_pos + 4, h_msg.length-h_pos-4);
		h_pos = posZeile(h_msg);
	}
	return h_Zeilen;
}

function posZeile(text) {
	p_br = text.indexOf("<br>");
	p_hr = text.indexOf("<hr>");
	if ((p_br >= 0) && (p_hr >= 0))	return Math.min(p_br, p_hr);
	if (p_br >= 0)			return p_br;
	if (p_hr >= 0)			return p_hr;
					return -1;
}

function hideBallon() {
	if (Ballon == null) return;
	crossHideObject(Ballon);
	ballonShow=false;
	crossMoveTo(Ballon, -200, 0);
}

// der Maus folgen
function cursorMove(e) {
	var posX, posY;
	
	crossMousePosition(e);

	if (ballonShow) {

		switch (b_Dir) {
			case 0:		// rechts
			posX = crossMouseX + ballonSpace; 
			break;
			case 1:		// links
			posX = crossMouseX-b_Breite-ballonSpace;
			break;
			case 2:		// Mitte
			posX = crossMouseX-(b_Breite/2)-ballonSpace;
			break;
		}
		if (b_VDir==0) {posY = crossMouseY + ballonSpace;}
//		else {posY = crossMouseY - ballonChangeVDir;}
		else {posY = crossMouseY - b_Hoehe;}
		crossMoveTo(Ballon, posX, posY)
	}
}
