// Name: bigtip
// Usage:
//   This file should be included in the body of the document, not the
//   head.  It seems to be happiest right after the <body> tag.
//
//   Elsewhere in the document, wherever you would normally use title="..."
//   with a plaintext tip, you should use the following instead:
//
//       onMouseOver="bigtip('some HTML text')" onMouseOut="bigtip()"
//
//   Note that the tip text is full-featured HTML.  If the tip uses
//   apostrophes, you can either use an HTML-style &acute; or a
//   JavaScript-style \' escape.  To force a line break, use <br> or
//   any other HTML tag that breaks lines.  You can also use fonts,
//   tables, images, or any other HTML feature.
//
//   The bigtip() function also supports some other parameters.  The
//   second parameter is the width of the tip, unless it is 0 or omitted.
//   The third parameter is the background color unless "" or omitted.
//
//   Alternatively, for the special case where the tooltip which consists
//   of multiple name/value pairs you can use the bigtippairs() function
//   instead.  This uses bigtip() internally, but saves you from the effort
//   of generating HTML table tags.  The bigtippairs() function is used as:
//
//	onMouseOver="bigtippairs('name1','value1',...)" onMouseOut="bigtip()"
//
//////////////////////////////////////////////////////////////////////////////

// Configuration constants
var bigtipoffsetX = 12;		      // x offset of tooltip, relative to mouse
var bigtipoffsetY = 10;		      // y offset of tooltip, relative to mouse
var bigtipfollow = false;	      // whether tip moves when mouse moves
var bigtipcolor = "#ffffc0";	      // default background color
var bigtipborder = "solid thin black";// border style

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

//write out tooltip DIV
document.write('<div id="bigtip" style="border:'+bigtipborder+';padding:1;z-index:1;position:absolute;visibility:hidden;"></div>')

var bigtipie = document.all // MSIE,Opera
var bigtipns6 = document.getElementById && !bigtipie  // Netscape,Mozilla,Firefox
var bigtipenable = false
var bigtipobj = "";
if (bigtipie)
    bigtipobj = document.all["bigtip"]
else if (bigtipns6)
    bigtipobj = document.getElementById("bigtip")

// This function assigns the text, and optionally the background color or width,
// to use for the next big tip.
function bigtip(htmltext, colorname, width)
{
    if (bigtipns6||bigtipie){
	if (typeof htmltext == "undefined" || htmltext == "") {
	    /* no text given, so hide the tip */
	    bigtipenable = false;
	    bigtipobj.style.visibility = "hidden";
	    bigtipobj.style.left = "-1000px";
	} else {
	    /* store the text, and optionally other attributes */
	    if (typeof width!="undefined" && width != 0)
		bigtipobj.style.width = width + "px";
	    else
		bigtipobj.style.width = null;
	    if (typeof colorname!="undefined" && colorname!="")
		bigtipobj.style.backgroundColor = colorname;
	    else
		bigtipobj.style.backgroundColor = bigtipcolor;
	    bigtipobj.innerHTML = htmltext;
	    bigtipobj.style.visibility = "hidden";// bigtipposition() will make it visible
	    bigtipenable = true;
	    return false
	}
    }
}

// This function should be called whenever the mouse moves.  It causes the
// tip to be shown.
function bigtipposition(e)
{
    if (bigtipenable && (bigtipfollow || bigtipobj.style.visibility == "hidden")){
	var ietruebody;
	if (bigtipie) {
	    if (document.compatMode && document.compatMode != "BackCompat")
		ietruebody = document.documentElement;
	    else
		ietruebody = document.body;
	}

        var curX = bigtipns6 ? e.pageX : event.clientX + ietruebody.scrollLeft;
        var curY = bigtipns6 ? e.pageY : event.clientY + ietruebody.scrollTop;

        //Find out how close the mouse is to the corner of the window
        var winwidth;
        var winheight;
        var rightedge;
        var bottomedge;
	if (bigtipie && !window.opera) {
	    winwidth = ietruebody.clientWidth;
	    winheight = ietruebody.clientHeight;
	    rightedge = winwidth-event.clientX - bigtipoffsetX;
	    bottomedge = winheight-event.clientY - bigtipoffsetY;
	} else {
	    winwidth = window.innerWidth - 20;
	    winheight = window.innerHeight - 20;
	    rightedge = winwidth - e.clientX - bigtipoffsetX;
	    bottomedge = winheight - e.clientY - bigtipoffsetY;
	}
        var leftedge = (bigtipoffsetX < 0) ? bigtipoffsetX * (-1) : -1000;

        //if the horizontal distance isn't enough to accommodate the width of the tip
        if (rightedge < bigtipobj.offsetWidth)
            bigtipobj.style.left = curX - bigtipobj.offsetWidth + "px";
        else if (curX<leftedge)
            bigtipobj.style.left = "5px";
        else
            bigtipobj.style.left=(curX+bigtipoffsetX)+"px"

        //same concept with the vertical position
        if (bottomedge<bigtipobj.offsetHeight)
            bigtipobj.style.top = curY - bigtipobj.offsetHeight - bigtipoffsetY + "px";
        else
            bigtipobj.style.top = curY + bigtipoffsetY + "px";
        bigtipobj.style.visibility = "visible";
    }
}

// Arrange for bigtipposition() to be called whenever the mouse moves
document.onmousemove = bigtipposition;

// This function returns a single row for a given name/value pair.  It is used
// by the bigtippairs() function.
function bigtiprow(name, value)
{
    if (typeof value == "undefined" || value == "")
	return "";
    if (typeof name == "undefined" || name == "")
	return "<tr>" + value + "</tr>";
    return "<tr><td style=\"vertical-align:top;font-weight:bold;\">" + name + ":</td><td>" + value + "</td></tr>";
}

// This is a convenience function for displaying a bigtip that shows a
// collection of name/value pairs.  The names are shown on the left in bold,
// and their values are shown on the right in normal font.  If the value is
// null or "" then the whole row is skipped.  If the name is null or "" then
// the value should be the entire row, with suitable <td> tags inside.
// The name and value strings are HTML -- in most cases names will be simple
// words, but you may want to be careful about the values.  On the other hand,
// you can also use HTML to get some very creative values.
function bigtippairs(n1,v1, n2,v2, n3,v3, n4,v4, n5,v5, n6,v6, n7,v7, n8,v8, n9, v9, n10, v10, n11, v11, n12, v12, n13, v13, n14, v14, n15, v15)
{
    if (typeof n1 == "undefined") {
	bigtip();
	return;
    }
    var tip = "<table>";
    tip += bigtiprow(n1, v1);
    tip += bigtiprow(n2, v2);
    tip += bigtiprow(n3, v3);
    tip += bigtiprow(n4, v4);
    tip += bigtiprow(n5, v5);
    tip += bigtiprow(n6, v6);
    tip += bigtiprow(n7, v7);
    tip += bigtiprow(n8, v8);
    tip += bigtiprow(n9, v9);
    tip += bigtiprow(n10, v10);
    tip += bigtiprow(n11, v11);
    tip += bigtiprow(n12, v12);
    tip += bigtiprow(n13, v13);
    tip += bigtiprow(n14, v14);
    tip += bigtiprow(n15, v15);
    tip += "</table>";
    bigtip(tip);
}

//ex:se sw=4 smarttab bd="syntax java":
