/*
  für Browserkompatibilität:
    - http://de.selfhtml.org/dhtml/beispiele/navigation.htm
    - http://suche.de.selfhtml.org/cgi-bin/such.pl?suchausdruck=mausposition&lang=on&feld=alle&index_1=on&index_2=on&index_3=on&index_4=on&index_5=on&hits=100
*/





/* Objekte in der DOM zu finden (3rd) */

  function boxInternFindObj (n, d)													// n = name; d = Referenz auf document-Objekt, falls in Layer gesucht wird (rekursive Aufrufe), sonst null
  {
  	var i, x;                                     					// i = Zählvariable; x = gesuchtes Objekt
  	if(!d)                                       						// Falls kein rekursiver Aufruf
  		d = document;                              						// d auf document initialisieren, sonst wird document eines Layers verwendet
  	if(!(x = d[n]) && d.all)                         				// Zunächst Zuweisung von benanntem Objekt im document-Objekt (funktioniert in NS4.x und IE>=4)
  		x = d.all[n];                              						// Falls Objekt noch nicht gefunden und all-Collection existiert (MSIE), Objekt in all suchen
  	for (i = 0; !x && i < d.forms.length; i++)           		// Solange Objekt noch nicht gefunden, alle Formular-Elemente durchsuchen
  		x = d.forms[i][n];                         						// Zuweisung des benannten Formularfeldes in i-tem Formular (null, falls nicht definiert)
  	for(i = 0; !x && d.layers && i < d.layers.length; i++) 	// Falls noch nicht gefunden und layers existiert (NS4)
  		x = menuInternFindObj (n, d.layers[i].document);    						// alle Layers durchsuchen per rekursivem Aufruf mit neuem document-Objekt
  	if(!x && d.getElementById)                   						// Falls noch nicht gefunden und DOM-kompatibler Browser (NS>=6, Opera)
  		x = d.getElementById (n);                   					// DOM-Methode zur Suche verwenden
  	return x;                                    						// Objekt zurückgeben (immer noch null, falls nicht gefunden)
  }





/* Box-Funktionen */

  var warteZeit = 500; // [ms]
  var boxStyleCss = 'border:1px solid #666666; background-color:#ffffff; color:#000000;';

  var boxObj;
  var timeOutVar;
  var showFlag = false;
  var hidableFlag = true;
  var aktX;
  var aktY;
  //var tt = false;

  function initBox () {
    boxObj = boxInternFindObj("boxDiv");
    document.onmousemove = mouseMove;
  }

  function mouseMove (Ereignis) {
    if (Ereignis != "") {
      if (!Ereignis)
        Ereignis = window.event;
      aktX = Ereignis.clientX;
      aktY = Ereignis.clientY;
    }
    if (showFlag) {
      var xOffset = 0;
      var yOffset = 0;
      if (typeof window.pageYOffset == "number") {
        xOffset = window.pageXOffset;
        yOffset = window.pageYOffset;
      } else if (typeof document.body.scrollTop == "number") {
        xOffset = document.body.scrollLeft;
        yOffset = document.body.scrollTop;
      }
      var objBreite = 0;
      var objHoehe = 0;
      if (typeof boxObj.offsetWidth == "number") { // IE
        objBreite = boxObj.offsetWidth;
        objHoehe = boxObj.offsetHeight;
      } else if (typeof boxObj.pixelWidth == "number") { // Firefox
        objBreite = boxObj.pixelWidth;
        objHoehe = boxObj.pixelHeight;
      }
      var fensterBreite = 0;
      var fensterHoehe = 0;
      if (typeof window.innerWidth == "number") { // Firefox
        fensterBreite = window.innerWidth;
        fensterHoehe = window.innerHeight;
        //alert("innerWidth = " + fensterBreite);
      } else if (typeof document.body.offsetWidth == "number") { // IE
        fensterBreite = document.body.offsetWidth;
        fensterHoehe = document.body.offsetHeight;
        //alert("offsetWidth = " + fensterBreite);
      }
      var xPos = aktX + 20; // rechts neben Mouse anzeigen
      var yPos = aktY + 20; // unter Mouse anzeigen
      fensterBreite -= 30;
      fensterHoehe -= 30;
      var xAnschlag = false;
      if (aktX + 20 + objBreite > fensterBreite) { // passt NICHT rechts neben Maus?
        if (aktX - 20 - objBreite > 0) // passt links neben Maus?
          xPos = aktX - 20 - objBreite; // links neben Mouse anzeigen
        else {
          xAnschlag = true;
          if (aktX > fensterBreite / 2)
            xPos = fensterBreite - objBreite; // rechts fix am Rand
          else
            xPos = 10; // links fix am Rand
        }
      }
      if (aktY + 20 + objHoehe > fensterHoehe) { // passt NICHT unten von Maus?
        if (aktY - 20 - objHoehe > 0) // passt oben von Maus?
          yPos = aktY - 20 - objHoehe; // oben von Mouse anzeigen
        else if (xAnschlag)
          ; // unten von Mouse anzeigen über den Fensterrand hinaus, da sonst die Maus über die Box wandern würde
        else
          if (aktY > fensterHoehe / 2)
            yPos = fensterHoehe - objHoehe; // unten fix am Rand
          else
            yPos = 10; // oben fix am Rand
      }
      boxObj.style.left = (xPos + xOffset) + "px";
      boxObj.style.top = (yPos + yOffset) + "px";
    }
  }

  function showBox (tempObj, inhalt) {
    window.clearTimeout(timeOutVar);
    timeOutVar = window.setTimeout("showBoxNow('', \"" + inhalt + "\")", warteZeit);
    if (!tempObj.onmouseout)
      tempObj.onmouseout = hideBox;
  }

  function hideBox () {
    if (boxObj != null) {
      if (hidableFlag) {
        window.clearTimeout(timeOutVar);
        boxObj.style.visibility = "hidden";
        boxObj.innerHTML = "";
        makeIframeIntoBox();
        showFlag = false;
      } else
        hidableFlag = true;
    }
  }

  function showBoxNow (tempObj, inhalt) {
    window.clearTimeout(timeOutVar);
    showFlag = true;
    inhalt = "<table cellspacing='0' cellpadding='2'><tr><td style='" + boxStyleCss + "'>" + inhalt + "</td></tr></table>";
    boxObj.innerHTML = inhalt;
    makeIframeIntoBox();
    mouseMove("");
    boxObj.style.visibility = "visible";
    if (tempObj != "")
      if (!tempObj.onmouseout)
        tempObj.onmouseout = hideBox;
  }

  function showBoxStaticNow (tempObj, inhalt) {
    window.clearTimeout(timeOutVar);
    showFlag = true;
    inhalt = "<table cellspacing='0' cellpadding='2'><tr><td style='" + boxStyleCss + "'>" + inhalt + "</td></tr></table>";
    boxObj.innerHTML = inhalt;
    makeIframeIntoBox();
    mouseMove("");
    showFlag = false;
    boxObj.style.visibility = "visible";
  }

  function showBoxStaticNowWaitForHidable (tempObj, inhalt) {
    hidableFlag = false;
    showBoxStaticNow(tempObj, inhalt);
  }

  function schowBoxScreenFrameNow (url) {
    var fensterBreite = 0;
    var fensterHoehe = 0;
    if (typeof window.innerWidth == "number") { // Firefox
      fensterBreite = window.innerWidth;
      fensterHoehe = window.innerHeight;
      //alert("innerWidth = " + fensterBreite);
    } else if (typeof document.body.offsetWidth == "number") { // IE
      fensterBreite = document.body.offsetWidth;
      fensterHoehe = document.body.offsetHeight;
      //alert("offsetWidth = " + fensterBreite);
    }

    hidableFlag = false;
    window.clearTimeout(timeOutVar);
    showFlag = true;
    inhalt = "<table cellspacing='0' cellpadding='2'><tr><td style='" + boxStyleCss + "'><iframe name='screenFrame' src='" + url + "' width='" + (fensterBreite - 35) + "' height='" + (fensterHoehe - 20) + "' marginheight='0' marginwidth='0' scrolling='no' noresize='noresize' frameborder='0'></iframe></td></tr></table>";
    boxObj.innerHTML = inhalt;
    makeIframeIntoBox();
    mouseMove("");
    showFlag = false;
    boxObj.style.visibility = "visible";

    var xOffset = 0;
    var yOffset = 0;
    if (typeof window.pageYOffset == "number") {
      xOffset = window.pageXOffset;
      yOffset = window.pageYOffset;
    } else if (typeof document.body.scrollTop == "number") {
      xOffset = document.body.scrollLeft;
      yOffset = document.body.scrollTop;
    }
    boxObj.style.left = (xOffset + 5) + "px";
    boxObj.style.top = (yOffset + 5) + "px";
  }
  
  function makeIframeIntoBox () {
    if (browser.isIE) {
      iframeInhalt = '<iframe id="boxIframe" src="javascript:;" style="position:absolute; filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" width="' + boxObj.offsetWidth + '" height=" ' + boxObj.offsetHeight + ' " marginheight="0" marginwidth="0" scrolling="no" noresize="noresize" frameborder="no"></iframe>';
      boxObj.innerHTML = iframeInhalt + boxObj.innerHTML;
    }
  }
