  /* * *
   * Script by Tilo Kussatz 2006.
   *
   * Displays a helpful popup right beneath the cursor when the visitor hovers
   * one of our friedly question mark links.
   * Takes into account the amout the page has been scrolled down or to the
   * right as well as everything else necessary to guarantee convenient popup
   * placement.
   *
   * Popup contents are loaded dynamically*) to keep the page size down for our
   * growing audience of more experienced members.
   *
   * For future reference, the ever-so-useful link I was lacking earlier today:
   *
   * 	http://www.quirksmode.org/viewport/compatibility.html
   * 	(very cool JS site, really)
   *
   * ----
   * *) Asynchronously even, as AJAX fans would tell you. I skipped the "AX"
   *    bit, though, and used just Asynchronous Javascript withOut XML ("AJOX").
   */

	var cursorX, cursorY, hovering, timer, topic;

	function help(topicId) {
		// Falls eine Topic-ID größer 0 angegeben wird, Hilfe anzeigen.
	  	if (topicId > 0 && !hovering) {
	  		hovering = true;
	  		topic = topicId
	  		window.clearTimeout(timer);
	  		fetchHelpTopic(topicId);
	  	}
	  	// Ansonsten: Hilfe wieder verstecken.
	  	else {
	  		hovering = false;
	  		timer = window.setTimeout("document.getElementById('help_text').style.display = 'none';", 333);
	  		timer = window.setTimeout("document.getElementById('medallien_text').style.display = 'none';", 333);
	  	}
  	}

  	function fetchHelpTopic(id) {
  		// Holt den Hilfetext in den unsichtbaren IFrame.
  		// Von dort aus wird, sobald die Seite geladen ist, showHelp() aufgerufen.
		document.getElementById('temp_text').src = '/fussball/help/'+id;
	}
	function showHelp() {
		// Zwischenschritt als Rudiment aus vergangenen Zeiten; schaden wird es nicht.
		setTimeout('showHelpNow();', 300);
	}
	function showHelpNow() {
		// Hilfetext ins (noch unsichtbaren) <div> "help_text" schieben.
		if (topic > 1000) {
			document.getElementById('medallien_text').innerHTML = window.frames['temp_text'].document.getElementById('theBody').innerHTML;
		} else {
			document.getElementById('help_text').innerHTML = window.frames['temp_text'].document.getElementById('theBody').innerHTML;
		}

		// Falls die Maus inzwischen nicht schon wieder weg vom Link ist: Box positionieren + anzeigen.
		if (hovering)
			moveHelpBox();
	}

	function moveHelpBox() {
		if (topic > 1000) {
			helpBox = document.getElementById('medallien_text');
		} else {
			helpBox = document.getElementById('help_text');
		}

		var availX, availY;
		var scrollOffsetX, scrollOffsetY;

		if (self.pageYOffset) // all except Explorer
		{
			availX = self.innerWidth;
			availY = self.innerHeight;
			scrollOffsetX = self.pageXOffset;
			scrollOffsetY = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
			// Explorer 6 Strict
		{
			availX = document.documentElement.clientWidth;
			availY = document.documentElement.clientHeight;
			scrollOffsetX = document.documentElement.scrollLeft;
			scrollOffsetY = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			availX = document.body.clientWidth;
			availY = document.body.clientHeight;
			scrollOffsetX = document.body.scrollLeft;
			scrollOffsetY = document.body.scrollTop;
		}

		newX = cursorX + scrollOffsetX;
		newY = cursorY + scrollOffsetY;

		// Passt die Box komplett rechts neben den Cursor? Falls nicht, wird sie nach links geschoben.
		maxX = availX + scrollOffsetX - 250 - 30;
		if (newX > maxX) {
			newX = maxX;
		}

		// Okay - Box jetzt in Cursornähe positionieren.
		helpBox.style.left = newX + "px";
		helpBox.style.top = newY + "px";

		// Box anzeigen.
		helpBox.style.display = 'block';

		// Falls die Box nach unten aus dem sichtbaren Bereich gerutscht ist, korriegieren wir das hier.
		maxY = availY + scrollOffsetY - helpBox.offsetHeight - 30;
		if (newY > maxY) {
			newY = maxY;
			helpBox.style.top = newY + "px";
		}
	}

	function trackCursorPosition(evt) {
		// Egal wohin sich die Maus bewegt - wir halten es in zwei globalen Variablen fest, um später dranzukommen.

	  	if (document.all) { // Internet Explorer ahead!
			cursorX = event.clientX;
			cursorY = event.clientY;
	  	}
	  	else if (document.getElementById) { // good browser ahead!
			cursorX = evt.clientX;
			cursorY = evt.clientY;
	 	}
	}
	document.onmousemove = trackCursorPosition;