// Primary Code Block for Tooltip
// Written by Giovanni Glass

function Tip(whoAmI, obj)
{
        this.whoAmI  = "" + whoAmI;
        this.isIE    = (document.all) ? true : false;
        this.isMoz   = (!this.isIE && document.getElementById) ? true : false;
        this.isNS4   = (!this.isIE && !this.isMoz && document.layer) ? true : false;
        this.whatID  = "" + obj;
        this.stuff   = "";
        this.timerID;
        this.timerID2;
        this.showTooltip = function()
        {
                var totalArguments = arguments.length;
                var onOff = arguments[0] ? true : false; // set the visibility of the tooltip
                var arg1 = arguments[1];
                var arg2 = arguments[2];
                var arg3 = arguments[3];
                var arg4 = arguments[4];
                var menuTimeout = 0;  // duration before it disappears 
                var menuTimein = 800; // duration before it appears 
                this.stuff = arg1;

                if (onOff) {
                        clearTimeout(this.timerID);
                        this.timerID = setTimeout(this.whoAmI + '.tooltipShowHide(1, ' + this.whoAmI +  '.stuff, ' + arg2 + ', ' + arg3 + ', ' + arg4 + ');', menuTimein);
                } else {
                        clearTimeout(this.timerID);
                        this.timerID = setTimeout(this.whoAmI + '.tooltipShowHide(0)', menuTimeout);
                }
        }
      this.tooltipShowHide = function(state, code, offsetx, offsety)
        {
                this.tooltip = (this.isNS4) ? document.eval(this.whatID) : document.getElementById(this.whatID);

                if (this.timerID) clearTimeout(this.timerID);
                if (state) {
                        if (this.isNS4) {
                                var theString = "<LAYER onmouseout=\""
                                                + this.whoAmI
                                                + ".showTooltip(0)\">"
                                                + this.constructTip(code)
                                                + "</LAYER>";
                                this.tooltip.document.write(theString);
                                this.tooltip.document.close();
                                this.tooltip.left = offsetx;
                                this.tooltip.top  = offsety;
                                this.tooltip.visibility = "show";
                        } else if (this.isMoz || this.isIE) {
                                this.tooltip.innerHTML  = this.constructTip(code);
                                this.tooltip.style.left = offsetx;
                                this.tooltip.style.top  = offsety;
                                this.tooltip.style.visibility = "visible";
                        }
                } else {
                        if (this.isNS4) {
                                this.tooltip.visibility = "hidden";
                        } else if (this.isMoz || this.isIE) {
                                this.tooltip.style.visibility = "hidden";
                        }
                }
        }
        this.constructTip = function(code)
        {
                var tipFront = "";
                var tipBack  = "";
                return tipFront + code + tipBack;
        }
 
// ===================================================================
// The following code was created by Matt Kruse.
// Modified by Giovanni Glass (giovanniglass.com)
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================
        this.getAnchorPosition = function(anchorname)
        {
                var useWindow=false;
                var coordinates=new Object();
                var x=0,y=0;
                var use_gebi=false, use_css=false, use_layers=false;
                if (document.getElementById) { use_gebi=true; }
                else if (document.all) { use_css=true; }
                else if (document.layers) { use_layers=true; };
                if (use_gebi && document.all) {
                        x=this.AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
                        y=this.AnchorPosition_getPageOffsetTop(document.all[anchorname]);
                } else if (use_gebi) {
                        var o=document.getElementById(anchorname);
                        x=this.AnchorPosition_getPageOffsetLeft(o);
                        y=this.AnchorPosition_getPageOffsetTop(o);
                } else if (use_css) {
                        x=this.AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
                        y=this.AnchorPosition_getPageOffsetTop(document.all[anchorname]);
                } else if (use_layers) {
                        var found=0;
                        for (var i=0; i<document.anchors.length; i++) {
                                if (document.anchors[i].name==anchorname) { found=1; break; };
                        }
                        if (found==0) {
                                coordinates.x=0; coordinates.y=0; return coordinates;
                        }
                        x=document.anchors[i].x;
                        y=document.anchors[i].y;
                } else {
                        coordinates.x=0; coordinates.y=0; return coordinates;
                }
                coordinates.x=x;
                coordinates.y=y;
                return coordinates;
        }
        this.AnchorPosition_getPageOffsetLeft = function(el)
        {
                var ol = el.offsetLeft;
                while ((el=el.offsetParent) != null) { ol += el.offsetLeft; };
                return ol;
        }
        this.AnchorPosition_getPageOffsetTop = function(el)
        {
                var ot = el.offsetTop;
                while((el=el.offsetParent) != null) { ot += el.offsetTop; };
                return ot;
        }
        this.getAnchorX = function(name)
        {
                var x = this.getAnchorPosition(name);
                return x.x;
        }
        this.getAnchorY = function(name)
        {
                var x = this.getAnchorPosition(name);
                return x.y;
        }
}
tipper = new Tip('tipper', "smallTooltip"); // instantiate this function



