/* This notice must be untouched at all times.



tooltip.js    v. 2.0

The latest version is available at http://www.walterzorn.de/



Copyright (c) 2002 Walter Zorn. All rights reserved.

Created 1. 12. 2002 by Walter Zorn <walter@kreuzotter.de>

Last modified: 20. 12. 2002



This software is provided "as is", without a warranty of any kind.

*/





///////////////// Global Tooltip Configuration  /////////////////////

var ttWidth        = 300;

var ttPadding      = 8;

var ttBorderColor  = '#495A76';

var ttBorderWidth  = 1;

var ttBgColor      = '#AFC4CD';

var ttBgImg        = '';

var ttFontFace     = 'verdana,lucida,arial,helvetica,sans-serif';

var ttFontColor    = '#495A76';

var ttFontSize     = '10px';

var ttFontWeight   = 'normal'; // alternative is 'bold';

var ttOffsetX      = 10;

var ttOffsetY      = 10;

/////////////////////////////////////////////////////////////////////







var tt_obj,                         // current tooltip

tt_objWidth = 0, tt_objHeight = 0,  // width and height of current tooltip

xlim = 0, ylim = 0,                 // right and bottom borders of visible client area

tt_wait = false,

tt_vis = false,                     // tooltip visibility flag

tt_dwn = false;                     // true if tooltip below mousepointer





var tt_db = (document.compatMode && document.compatMode != 'BackCompat')? document.documentElement : document.body? document.body : null,

tt_n = navigator.userAgent.toLowerCase();





// Browser flags

var tt_op = (window.opera && document.getElementById)? true : false,

tt_ie = tt_n.indexOf('msie') != -1 &&

        document.all &&

        tt_db &&

        !tt_op,

tt_n4 = navigator.appName + parseInt(navigator.appVersion) == 'Netscape4' && document.layers,

tt_n6 = (tt_n6i = tt_n.indexOf('gecko')) != -1 ||

        tt_n.indexOf('galeon') != -1,

tt_kqi = tt_n.indexOf('konq'),

tt_kq = tt_kqi > -1,

tt_kqnew = tt_kq &&

        parseInt(tt_n.substring(tt_kqi + (5<<1))) > 2 &&

        tt_n.substring(tt_kqi + (5<<1), tt_kqi + (6<<1|1)) != '3.0';





tt_n = '';

if (tt_op)

{

        ttOffsetY += 5<<2;

        ttOffsetX -= 5<<1;

}





function tt_Int(x)

{

        var y;

        return isNaN(y = parseInt(x))? 0 : y;

}





// Substitute for String.replace;

// doesn't require regExp as to-be-replaced arg

function wzReplace(x, y)

{

        var ret = '',

        str = this,

        xI;

        while ((xI = str.indexOf(x)) != -1)

        {

                ret += str.substring(0, xI) + y;

                str = str.substring(xI + x.length);

        }

        return ret+str;

}

String.prototype.wzReplace = wzReplace;





function tt_Htm(tt, id, txt)

{

        var ttw   = (typeof tt.WIDTH != 'undefined')? tt.WIDTH  : ttWidth,

        ttpadd    = (typeof tt.PADDING != 'undefined')? tt.PADDING : ttPadding,

        ttbc      = (typeof tt.BORDERCOLOR != 'undefined')? tt.BORDERCOLOR : ttBorderColor,

        ttbw      = (typeof tt.BORDERWIDTH != 'undefined')? tt.BORDERWIDTH : ttBorderWidth,

        ttbgc     = (typeof tt.BACKGROUNDCOLOR != 'undefined')? tt.BACKGROUNDCOLOR : ttBgColor,

        ttbgimg   = (typeof tt.BACKGROUNDIMG != 'undefined')? tt.BACKGROUNDIMG : (typeof tt.BACKGROUNDIMAGE != 'undefined')? tt.BACKGROUNDIMAGE : ttBgImg,

        ttff      = (typeof tt.FONTFACE != 'undefined')? tt.FONTFACE : ttFontFace,

        ttfc      = (typeof tt.FONTCOLOR != 'undefined')? tt.FONTCOLOR : ttFontColor,

        ttfsz     = (typeof tt.FONTSIZE != 'undefined')? tt.FONTSIZE : ttFontSize,

        ttfwght   = (typeof tt.FONTWEIGHT != 'undefined')? tt.FONTWEIGHT : ttFontWeight;



        var y = '<div id="' + id + '" style="position:absolute;z-index:'+ (2<<8) + ';left:0px;top:0px;width:' + ttw + 'px;visibility:' + (tt_n4? 'hide' : 'hidden') + ';">\n';

        y += '<table border="0" cellpadding="0" cellspacing="0" bgcolor="' + ttbc + '" width="' + ttw + '">\n<tr>\n<td>\n';

        y += '<table border="0" cellpadding="' + ttpadd + '" cellspacing="' + ttbw + '" width="100%">\n';

        y += '<tr>\n<td bgcolor="' + ttbgc + '"' + (ttbgimg? ' background="' + ttbgimg + '"' : '') + '>\n';

        y += '<font style="font-family:' + ttff + ';color:' + ttfc + ';font-size:' + ttfsz + ';">';

        if (ttfwght == 'bold') y += '<b>';

        y += txt;

        if (ttfwght == 'bold') y += '<\/b>';

        y += '<\/font><\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n';

        return y;

}





function tt_Init()

{

        if (!(tt_op || tt_n4 || tt_n6 || tt_ie || tt_kq)) return;



        var htm = tt_n4? '<div style="position:absolute;"><\/div>' : '',

        lnk;

        for (var i = 0; i<document.links.length; i++)

        {

                if ((lnk = document.links[i]).onmouseover && lnk.onmouseover.toString().indexOf('escape(') != -1)

                {

                        htm += tt_Htm(

                                lnk,

                                'tOoLtIp'+i,

                                unescape(lnk.onmouseover()).wzReplace('& lt;','&lt;').wzReplace('& gt;','&gt;').wzReplace('& quot;','&quot;')

                        );



                        lnk.onmouseover = new Function('tt_Show("tOoLtIp'+i+'");');

                        lnk.onmouseout = tt_Hide;

                }

        }

        document.write(htm);

}





function tt_GetDiv(id)

{

        return (

                tt_n4? (document.layers[id] || null)

                : tt_ie? (document.all[id] || null)

                : (document.getElementById(id) || null)

        );

}





function tt_GetDivWidth()

{

        return (

                tt_n4? tt_obj.clip.width

                : tt_obj.style && tt_obj.style.pixelWidth? tt_obj.style.pixelWidth

                : tt_obj.offsetWidth

        );

}





function tt_GetDivHeight()

{

        return (

                tt_n4? tt_obj.clip.height

                : tt_obj.style && tt_obj.style.pixelHeight? tt_obj.style.pixelHeight

                : tt_obj.offsetHeight

        );

}





// Compat with DragDrop Lib: Ensure that z-index of tooltip is lifted beyond toplevel dragdrop element

function tt_SetDivZindex()

{

        var i = tt_obj.style || tt_obj;

        if (window.dd && dd.zIndex)

                i.zIndex = Math.max(dd.zIndex + 1, i.zIndex);

}





function tt_SetDivPos(x, y)

{

        var i = tt_obj.style || tt_obj;

        i.left = x;

        i.top = y;

}





function tt_ShowDiv()

{

        if (tt_n4) tt_obj.visibility = 'show';

        else tt_obj.style.visibility = 'visible';

        tt_vis = true;

}





function tt_HideDiv()

{

        if (tt_n4) tt_obj.visibility = 'hide';

        else tt_obj.style.visibility = 'hidden';

        tt_vis = false;

}





function tt_Show(id)

{

        if (tt_obj) tt_Hide();

        if (!(tt_op || tt_n4 || tt_n6 || tt_ie || tt_kq) || document.onmousemove) return;  // return if onmousemove currently active (for instance drag operation?)





        tt_obj = tt_GetDiv(id);

        if (tt_obj)

        {

                tt_objWidth = tt_GetDivWidth();

                tt_objHeight = tt_GetDivHeight();

                tt_dwn = true;



                xlim = tt_Int((tt_db && tt_db.clientWidth)? tt_db.clientWidth : window.innerWidth) +

                        tt_Int(window.pageXOffset || (tt_db? tt_db.scrollLeft : 0) || 0) -

                        tt_objWidth -

                        (tt_n4? 5<<2 : 0);



                ylim = tt_Int(window.innerHeight || tt_db.clientHeight) +

                        tt_Int(window.pageYOffset || (tt_db? tt_db.scrollTop : 0) || 0) -

                        tt_objHeight - ttOffsetY;



                tt_SetDivZindex();



                if (document.captureEvents)        document.captureEvents(Event.MOUSEMOVE);

                document.onmousemove = tt_Move;

        }

}





function tt_Move(e)

{

        if (!tt_obj) return;

        if (tt_n6 || tt_kq)

        {

                if (tt_wait) return;

                tt_wait = true;

                setTimeout('tt_wait = false;', 5);

        }





        e = e || window.event;

        //var e_x = (typeof e.pageX == 'number')? e.pageX : 0; // IE4 bug



        var x = tt_Int(e.pageX || e.clientX || 0) +

                tt_Int((tt_ie || tt_kqnew)? tt_db.scrollLeft : 0) +

                ttOffsetX;

        var y = tt_Int(e.pageY || e.clientY || 0) +

                tt_Int((tt_ie || tt_kqnew)? tt_db.scrollTop : 0);





        if (x > xlim) x = xlim;

        if (y > ylim || !tt_dwn && y > ylim-(6<<2))

        {

                y -= (tt_objHeight + 5);

                tt_dwn = false;

        }

        else

        {

                y += ttOffsetY;

                tt_dwn = true;

        }



        tt_SetDivPos(x, y);

        if (!tt_vis) tt_ShowDiv();

}





function tt_Hide()

{

        if (typeof tt_obj != 'undefined' && tt_obj)

        {

                tt_HideDiv();

                tt_obj = null;

                if (document.releaseEvents)        document.releaseEvents(Event.MOUSEMOVE);

                document.onmousemove = null;

        }

}





tt_Init();

tt_Hide();
