/*
 * infobox.js - Information in style.
 *
 * :tabSize=4:indentSize=4:noTabs=false:
 * :folding=explicit:collapseFolds=1:
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the 
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

// TODO: Make this work in IE. Argh.
 
var posX;	// Mouse X position
var posY;	// Mouse Y position
 
// Rudimentary browser detection.
var isOperaIE = document.all ? true : false;

if(isOperaIE)
{
	document.onmousemove=getMousePos_Opera;
}
else
{
	// This *should* work in all browsers that claim to support DOM2, but
	// only Mozilla supports it correctly. Sigh.
	document.addEventListener("mousemove", getMousePos, true);
}

/**
 * Retrieves the position of the mouse cursor in Mozilla and iCab browsers.
 */
function getMousePos(e)
{
	posX = e.pageX;
	posY = e.pageY;
}

/**
 * Retrieves the position of the mouse cursor in Opera. This would also work
 * in IE6 except that IE6 puts itself in "standards compliance" mode when it
 * sees a DOCTYPE, and apparently "standards compliance" means "screw
 * standards, let's eat pie" in Microsoftese. 
 */
function getMousePos_Opera()
{
	posX = document.body.scrollLeft + event.clientX;
	posY = document.body.scrollTop + event.clientY;
}
 
/**
 * Displays an infobox at the location of the mouse cursor.
 *
 * @param source Source element.
 * @param content Content to be displayed in the infobox.
 * @param type Content type. Either "text" or "image".
 */ 
function infoBoxOn(source, content)
{
	var infobox = document.getElementById("infoBox");
	
	infobox.innerHTML = content;
	
	infobox.style.left    = posX + "px";
	infobox.style.top     = posY + "px";
	infobox.style.display = "block";
}

/**
 * Turns the infobox off.
 */
function infoBoxOff()
{
	var infobox = document.getElementById("infoBox");
	
	infobox.style.display = "none";
}