/* 
*
* file containing functions to display a ToolTip
*
* To create a tooltip do the following
* - create an empty <div> or <span> element with an id="tooltip"
*      <div style="display:none;position:absolute" id="tooltip"></div>
*
* HINT: If the tooltip flickers when using Netscape 7.1, try to move the
*       the tooltip-tag (above) to a different position on your page.
*       Avoid positions near the top border of a page!
*
* - add the appropriate headline and text in *each* countries' main.cfg
* - add a defintion for this text in lib/js/tooltips_text.js
* - call the tooltip in your code by adding
*     onMouseOver="showtip(<number>,event[,hideitem])"
*   to your code.
* - hide the tooltip by adding
*     onMouseOut=hidetip([showitem])
*   to your code.
*   [showitem] - (optional) th id of a selectbox that need to be display after
*                the tooltip is gone (see above)
*   e.g. hidetip('eulang')
*
* To change the layout of the displayed tooltip, change the HTML code in
* the function tipwindow() below.
*
*/

/* ------------------------------------ global config values, change as desired --------- */
var g_delayShow = 1000;   // Delay before Tooltip appears (in msec.)

/* -------------------- global variables to store timeout handles, DON'T TOUCH! --------- */
var g_iTipTimeOutID  = null;

/* ------------------------------------ functions --------------------------------------- */

/* 
* showtip() - call this fuction from your HTML code
*
*   tooltipNumber - the text number you correspondig to items tooltips_text.js & main.cfg
*   event - the Event object
*   hideitem - (optional) the id of a selectbox that will shine thru your
*               tooltip if you use the Internet Explorer
*   e.g. showtip(2,event,'eulang')
*
* HINT: This function is only a wrapper function that sets the timeout for
*       the 'real' tooltip function to be called
*/
function showtip(tooltipNumber,e,hideitem)
{
  deActivateToolTip();
  curevent=(typeof event=='undefined'? e : event);
  var x = curevent.clientX;
  var y = curevent.clientY;

  /* clear title tag from element to avoid overlapping with tooltip
  *  code taken from http://www.quirksmode.org/js/events_properties.html#target
  *  HINT: although onMouseOver has been defined in the <a href>-tag, the
  *        event.target is an HTMLImage, so the title tag has to be defined
  *        in the <img>!
  */
  var targ;
	if (curevent.target)  // use target in Mozilla Browsers
    targ = curevent.target;
	else if (curevent.srcElement) // use srcElement in Microsoft IE
    targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
  if(targ.title)
    targ.title="";
  
  g_iTipTimeOutID = setTimeout("showTooltip(" + tooltipNumber + "," + x + "," + y + ",\"" + hideitem + "\");", g_delayShow);
}

/* showTooltip() - actual function to display the tooltip 
*
* DO NOT CALL THIS FUNCTION DIRECTLY! USE showtip() instead!!
*/
function showTooltip(item, x, y, hideitem)
{
  // ToolTips on Safari and Netscape currently don't work
  if (navigator.userAgent.indexOf("Safari") == -1)
  {
    document.getElementById('tooltip').innerHTML=
      tipwindow(tooltip_headline[item], tooltip_text[item],tooltip_icon[item]);
    document.getElementById('tooltip').style.left=x;
    document.getElementById('tooltip').style.top=y;
    document.getElementById('tooltip').style.display='';

    /* hide select box in IE */
  	if (hideitem)
    {
  	  if(document.getElementById(hideitem))
      {
        document.getElementById(hideitem).style.visibility="hidden";
      }
    }
  }
}

function hidetip(showitem)
{
  document.getElementById('tooltip').style.display='none';

	/* show selectbox in IE */
  if (showitem)
  {
	  if ( document.getElementById(showitem))
    {
      document.getElementById(showitem).style.visibility="visible";
    }
  }
  deActivateToolTip();

}

function deActivateToolTip()
{
   if(g_iTipTimeOutID != null)
      clearInterval(g_iTipTimeOutID);
}

function tipwindow(headline, text, icon)
{
  tipwin  = '<table border="0" width="250" cellspacing="6" style="background-color:#003366; border: 1px solid #cccc99;">';
  tipwin += '  <tr>';
  tipwin += '    <td><img src="img/katharina4evertooltip.png"/></td>';
  tipwin += '  </tr>';
  tipwin += '  <tr>';
  tipwin += '    <td class="trenner">';

  if (icon != "")
  {
    tipwin += '&nbsp;<img src="' + icon + '" alt="" style="vertical-align:middle">';
  }

  tipwin += '      &nbsp;<b>' + headline + '</b></td>';
  tipwin += '  </tr>';
  tipwin += '  <tr>';
  tipwin += '    <td class="tooltiptext">' + text +'</td>';
  tipwin += '  </tr>';
  tipwin += '</table>';

	return tipwin;
}