/*=========================================*/
/*  overLIB 3.51  --  This notice must remain untouched at all times.*/
/*  Copyright Erik Bosrup 1998-2002. All rights reserved.*/
/*  By Erik Bosrup (erik@bosrup.com).  Last modified 2002-11-01.*/
/*  Portions by Dan Steinman (dansteinman.com). Additions by other people are*/
/*  listed on the overLIB homepage.*/
/*  Get the latest version at http:=www.bosrup.com/web/overlib/*/
/*  This script is published under an open source license. Please read the license*/
/*  agreement online at: http:=www.bosrup.com/web/overlib/license.html*/
/*  If you have questions regarding the license please contact erik@bosrup.com.*/
/*  This script library was originally created for personal use. By request it has*/
/*  later been made public. This is free software. Do not sell this as your own*/
/*  work, or remove this copyright notice. For full details on copying or changing*/
/*  this script please read the license agreement at the link above.*/
/*  Please give credit on sites that use overLIB and submit changes of the script*/
/*  so other people can use them as well. This script is free to use, don't abuse.*/
/*=========================================*/
/*  Rewritten october for hoverpopup - 2004 - Torben Wilhelmsen */
/*=========================================*/

var hoverdivblock = self;
var hoverpop_timerid = 0;
var hoverpop_allowmove = 0;
var hoverpop_x = 0;
var hoverpop_y = 0;
var hoverpop_showingsticky = 0;
var hoverpop_removecounter = 0;

/* Our layer*/
var over = null;

/* Decide browser version*/
var ns4 = (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) == 4);
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
if (ie4) var docRoot = 'document.body';
var ie5 = false;
if (ns4) {
	var oW = window.innerWidth;
	var oH = window.innerHeight;
	window.onresize = function () {if (oW!=window.innerWidth||oH!=window.innerHeight) location.reload();}
	}
/* Microsoft Stupidity Check(tm).*/
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		if(document.compatMode && document.compatMode == 'CSS1Compat') docRoot = 'document.documentElement';
		ie5 = true;
		}
	if (ns6) {
		ns6 = false;
		}
	}
/* Use to adjust for Mozilla browser window width*/
var gecko = (navigator.userAgent.indexOf('Gecko') > 0);

/* Capture events, alt. diffuses the overlib function.*/
if ( (ns4) || (ie4) || (ns6)) {
	document.onmousemove = mouseMove
	if (ns4) document.captureEvents(Event.MOUSEMOVE)
	} 
else {
	hoverpopup = no_hoverpopup;
	nd = no_hoverpopup;
	ver3fix = true;
	}

/* Fake function for 3.0 users.*/
function no_hoverpopup() {
	return ver3fix;
	}

/*=========================================*/
/* PUBLIC FUNCTIONS*/
/*=========================================*/

/* Loads parameters into global runtime variables.*/
function hoverpopup() {
	var ar = arguments;
	statusmessage = "";
	hoverdiv = ar[0]
	dosticky = parseInt(ar[1]);
	popuptimeout = parseInt(ar[2]);
	offset = ar[3].split(',');
	offsetx = parseInt(offset[0]);
	offsety = parseInt(offset[1]);
	hoverdivblockwidth = parseInt(ar[4]);
	if (hoverdivblockwidth < 0) hoverdivblockwidth = 300;
	
	/* Special for frame support, over must be reset...*/
	if ( (ns4) || (ie4) || (ns6) ) {
		if (over) cClick();
		hoverdivblock = self;
		if (ns4) over = hoverdivblock.document[hoverdiv]
		if (ie4) over = hoverdivblock[hoverdiv].style
		if (ns6) over = hoverdivblock.document.getElementById(hoverdiv);
		}

	return hoverpopup_do();
	}

/* Clears popups if appropriate*/
function nd() {
	if ( hoverpop_removecounter >= 1 ) { hoverpop_showingsticky = 0 };
	if ( (ns4) || (ie4) || (ns6) ) {
		if ( hoverpop_showingsticky == 0 ) {
			hoverpop_allowmove = 0;
			if (over != null) hoverpop_hide(over);
			}
		else {
			hoverpop_removecounter++;
			}
		}
	return true;
	}

/* This function decides what it is we want to display and how we want it done.*/
function hoverpopup_do() {

	/* We want it to stick!*/
	if (dosticky) {
		if (hoverpop_timerid > 0) {
			clearTimeout(hoverpop_timerid);
			hoverpop_timerid = 0;
			}
		hoverpop_showingsticky = 1;
		hoverpop_removecounter = 0;
		}
	hoverpop_allowmove = 0;

	/* Initiate a timer for timeout*/
	if (popuptimeout > 0) {
		if (hoverpop_timerid > 0) clearTimeout(hoverpop_timerid);
		hoverpop_timerid = setTimeout("cClick()", popuptimeout);
		}

	/* Show layer*/
	disp(statusmessage);

	/* Stickies should stay where they are.	*/
	if (dosticky) hoverpop_allowmove = 0;

	return (statusmessage != '');
	}


/*=========================================*/
/* HANDLING FUNCTIONS*/
/*=========================================*/

/* Displays the popup*/
function disp() {
	if ( (ns4) || (ie4) || (ns6) ) {
		if (hoverpop_allowmove == 0) 	{
			placeLayer();
			hoverpop_show(over);
			hoverpop_allowmove = 1;
			}
		}
	}

/* Decides where we want the popup.*/
function placeLayer() {
	var placeX, placeY;
	
	winoffset = (ie4) ? eval('hoverdivblock.'+docRoot+'.scrollLeft') : hoverdivblock.pageXOffset;
	if (ie4) iwidth = eval('hoverdivblock.'+docRoot+'.clientWidth');
	if (ns4 || ns6) iwidth = hoverdivblock.innerWidth;
	
	/* be sure to get free from the edge if scrollbars*/
	if (gecko) iwidth-= 20;
	
	placeX = hoverpop_x+offsetx;
	if ( (eval(placeX) + eval(hoverdivblockwidth)) > (winoffset + iwidth) ) {
		placeX = iwidth + winoffset - hoverdivblockwidth;
		if (placeX < 0) placeX = 0;
		}
	
	scrolloffset = (ie4) ? eval('hoverdivblock.'+docRoot+'.scrollTop') : hoverdivblock.pageYOffset;

	placeY = hoverpop_y + offsety;
	hoverpop_move(over, placeX, placeY);
	}

/* Moves the layer*/
function mouseMove(e) {
	if ( (ns4) || (ns6) ) {hoverpop_x=e.pageX; hoverpop_y=e.pageY;}
	if (ie4) {hoverpop_x=event.x; hoverpop_y=event.y;}
	if (ie5) {hoverpop_x=eval('event.x+hoverdivblock.'+docRoot+'.scrollLeft'); hoverpop_y=eval('event.y+hoverdivblock.'+docRoot+'.scrollTop');}
	
	if (hoverpop_allowmove == 1) {
		placeLayer();
		}
	}

/* The Close onMouseOver function for stickies*/
function cClick() {
	hoverpop_hide(over);
	hoverpop_showingsticky = 0;
	
	return false;
	}

/*=========================================*/
/* LAYER FUNCTIONS*/
/*=========================================*/

function hoverpop_show(obj) {
	if (ns4) obj.visibility = "show";
	else if (ie4) obj.visibility = "visible";
	else if (ns6) obj.style.visibility = "visible";
	}

function hoverpop_hide(obj) {
	if (ns4) obj.visibility = "hide";
	else if (ie4) obj.visibility = "hidden";
	else if (ns6) obj.style.visibility = "hidden";

	if (hoverpop_timerid > 0) clearTimeout(hoverpop_timerid);
	hoverpop_timerid = 0;
	self.status = "";
	}

function hoverpop_move(obj,xL,yL) {
	if ( (ns4) || (ie4) ) {
		obj.left = (ie4 ? xL + 'px' : xL);
		obj.top = (ie4 ? yL + 'px' : yL);
		}
	else if (ns6) {
		obj.style.left = xL + "px";
		obj.style.top = yL+ "px";
		}
	}
