// JavaScript code for Linktool of HyperScout.

// Identify Browser
var isNS4 = (document.layers) ? 1 : 0;
var isIE4 = (document.all) ? 1 : 0;
// Are CSS enabled?
//var style = ((isNS4 && document.testCSS) || isIE4) ? 1 : 0;
var style = (isNS4 || isIE4) ? 1 : 0;

// Netscape has to reload the page after a resize of window.
//if (isNS4) window.onload = lt_init;  // To many crashes!!!
function lt_init() { setTimeout("window.onresize = lt_redo", 1000); }
function lt_redo() { window.location.reload(); }

// Parameters
var lt_openDelay  = 800;  // ms delay before opening popup
var lt_reOpenDelay= 500;   // ms re-open within this time.

// Timers for delayed opening and immediate reopening of popups
var lt_openTimer   = null;
var lt_reOpenTimer = null;
var lt_popup = null;
var lt_visible = false;

//Set popup width
popupWidth = 400;
if (isNS4 && window.innerWidth < 410) popupWidth = Math.max( window.innerWidth - 30, 160);
// if (isIE4 && document.body.clientWidth < 410) {popupWidth = Math.max( document.body.clientWidth - 30, 160);}  //  Does not work before objects are generated, but then Netscape has bugs...

// This function is called, if a mouse is moved over a link
// it will activate a popup after a appropiate time.
function lt_activatePopup(e,id)
{
	if (!style) return;
	lt_popup = id;
	//lt_pointer = this.lt_pointer;
	if (isNS4) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = lt_checkMouseMove;
	lt_checkMouseMove(e);
}

// this function checks if the mouse was not moved for 300ms if it is over a link.
function lt_checkMouseMove(e)
{
	var delay = lt_openDelay;
	if (lt_openTimer) clearTimeout(lt_openTimer);
	if (lt_reOpenTimer) // IF it is a reopen: no delay.
		{ clearTimeout(lt_reOpenTimer); lt_reOpenTimer=null; delay=0; }
	var left = (isNS4) ? e.pageX : event.clientX + document.body.scrollLeft;
	var top  = (isNS4) ? e.pageY : event.clientY + document.body.scrollTop;
	if (delay>0) lt_openTimer = setTimeout("lt_showPopup("+left+", "+top+")",delay);
		else 		 lt_showPopup(left, top);

//	var Icon = (isNS4) ? document.lt_icon : document.all.lt_icon.style;
//	Icon.left = left+10;
//	Icon.top = top-20;
//	Icon.visibility = "visible";
}

// finally show the popup
function lt_showPopup(left,top)
{
//	if (isNS4) document.releaseEvents(Event.MOUSEMOVE);	
//	document.onmousemove=null;		// Deactivate mouse listener
	var waitElement = (isNS4) ? document.lt_wait : document.all.lt_wait.style;  // Get dummy-element
	waitElement.visibility = "hidden";	// hide
	var Element = (isNS4) ? document[lt_popup] : document.all[lt_popup];	// Get popup
	if (!Element) Element = (isNS4) ? document.lt_wait : document.all.lt_wait;	// take dummy if not existant
	left += 8;	// offset
	top += 18;
	if (isNS4) {	// Avoid clipping
		if (left - window.pageXOffset + Element.clip.width >= window.innerWidth)  left = Math.max(left - Element.clip.width, window.pageXOffset + 3);
		if (top - window.pageYOffset + Element.clip.height >= window.innerHeight) top  = Math.max(top - Element.clip.height, window.pageYOffset + 3);
	}
	else {
		if (left + Element.offsetWidth >= document.body.clientWidth) 	left = Math.max(left - Element.offsetWidth, document.body.scrollLeft + 3); 
		if (top + Element.offsetHeight >= document.body.clientHeight)  top  = Math.max(top - Element.offsetHeight, document.body.scrollTop +3);
	}
	if (isIE4) Element = Element.style;	// Style for IE4
	Element.left 	= left;	// Set position
	Element.top 	= top;
	Element.width	= popupWidth;
	Element.visibility = "visible";
	lt_visible		= true;	// popup is visible!
}

// Make the layer disapper, after the mouse leaves a link.
function lt_deactivatePopup()
{
	if (!style) return;	// CSS enabled?
	var Element = (isNS4) ? document[lt_popup] : document.all[lt_popup];  	// Create popup-element
	if (!Element) Element = (isNS4) ? document.lt_wait : document.all.lt_wait;   // Does division exist?
	if (isIE4) Element = Element.style;													// IE4: Add style.
	Element.visibility = "hidden";
//	var Icon = (isNS4) ? document.lt_icon : document.all.lt_icon.style;
//	Icon.visibility = "hidden";
	lt_popup = null;
	if (lt_openTimer) clearTimeout(lt_openTimer);
	if (isNS4) document.releaseEvents(Event.MOUSEMOVE);
	document.onmousemove=null;
   if (lt_visible) lt_reOpenTimer = setTimeout("lt_reOpenTimer=null;",lt_reOpenDelay);
	lt_visible		= false;
}

// Function to create popups.
function newPopup(name,text) {
	if (style) document.writeln('<div id="'+name+'" class="lt-table"><TABLE Border=0 Cellspacing=0 Cellpadding=1 width='+popupWidth+'><TR><TD bgcolor="#000000"><TABLE Border=0 Cellspacing=0 Cellpadding=1 width="100%">'+text+'</table></td></tr></table></div>');
} 

// Error message if popups are not available yet.
newPopup("lt_wait",'<TR><TD class="lt-td1">No link information available yet. Please wait...</TD></TR>');
//document.writeln('<div id="lt_icon" class="lt-icon"><img src="new.gif"></div>');
