// 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 = hs_init;  // To many crashes!!!
function hs_init() { setTimeout("window.onresize = hs_redo", 1000); }
function hs_redo() { window.location.reload(); }

// Parameters
var hs_openDelay  = 800;  // ms delay before opening popup
var hs_reOpenDelay= 500;   // ms re-open within this time.

// Timers for delayed opening and immediate reopening of popups
var hs_openTimer   = null;
var hs_reOpenTimer = null;
var hs_popup = null;
var hs_mouseicon = null;
var hs_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 hs_activate(e,id)
{
	if (!style) return;
	hs_popup = id + "_popup";
	hs_mouseicon = id + "_icon";
	if (isNS4) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = hs_checkMouseMove;
	hs_checkMouseMove(e);
}

// this function checks if the mouse was not moved for 300ms if it is over a link.
function hs_checkMouseMove(e)
{
	var delay = hs_openDelay;
	if (hs_openTimer) clearTimeout(hs_openTimer);
	if (hs_reOpenTimer) // IF it is a reopen: no delay.
		{ clearTimeout(hs_reOpenTimer); hs_reOpenTimer=null; delay=0; }
	var left = (isNS4) ? e.pageX : event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
	var top  = (isNS4) ? e.pageY : event.clientY + document.documentElement.scrollTop  + document.body.scrollTop;
	if (delay>0) hs_openTimer = setTimeout("hs_showPopup("+left+", "+top+")",delay);
		else 	 hs_showPopup(left, top);

	var Icon = (isNS4) ? document[hs_mouseicon] : document.all[hs_mouseicon];	// Get popup
	if (!Icon) return; // Icon = (isNS4) ? document.hs_no_icon : document.all.hs_no_icon;	// dummy if no icon
	if (isIE4) Icon = Icon.style;													// IE4: Add style.
	Icon.left = left+10;
	Icon.top = top-20;
	Icon.visibility = "visible";
}

// finally show the popup
function hs_showPopup(left,top)
{
//	if (isNS4) document.releaseEvents(Event.MOUSEMOVE);	
//	document.onmousemove=null;		// Deactivate mouse listener
	var waitElement = (isNS4) ? document.hs_wait_popup : document.all.hs_wait_popup.style;  // Get dummy-element
	waitElement.visibility = "hidden";	// hide
	var Element = (isNS4) ? document[hs_popup] : document.all[hs_popup];	// Get popup
	if (!Element) Element = (isNS4) ? document.hs_wait_popup : document.all.hs_wait_popup;	// 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 - 18, window.pageXOffset + 3);
		if (top - window.pageYOffset + Element.clip.height >= window.innerHeight) top  = Math.max(top - Element.clip.height - 33, window.pageYOffset + 3);
	}
	else {
		if (left + Element.offsetWidth >= document.body.clientWidth) 	left = Math.max(left - Element.offsetWidth - 18, document.body.scrollLeft + 3); 
		if (top + Element.offsetHeight >= document.body.clientHeight)  top  = Math.max(top - Element.offsetHeight - 33, 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";
	hs_visible		= true;	// popup is visible!
}

// Make the layer disapper, after the mouse leaves a link.
function hs_deactivate()
{
	if (!style) return;	// CSS enabled?
	var Element = (isNS4) ? document[hs_popup] : document.all[hs_popup];  	// Create popup-element
	if (!Element) Element = (isNS4) ? document.hs_wait_popup : document.all.hs_wait_popup;   // Does division exist?
	if (isIE4) Element = Element.style;													// IE4: Add style.
	Element.visibility = "hidden";
	hs_popup = null;
   
	if (hs_openTimer) clearTimeout(hs_openTimer);
	if (isNS4) document.releaseEvents(Event.MOUSEMOVE);
	document.onmousemove=null;
   if (hs_visible) hs_reOpenTimer = setTimeout("hs_reOpenTimer=null;",hs_reOpenDelay);
	hs_visible		= false;

	var Icon = (isNS4) ? document[hs_mouseicon] : document.all[hs_mouseicon];  	// Create popup-element
	if (!Icon) return; // Icon = (isNS4) ? document.hs_no_icon : document.all.hs_no_icon;   // Does division exist?
	if (isIE4) Icon = Icon.style;													// IE4: Add style.
	Icon.visibility = "hidden";
   hs_mouseicon = null;
}

// Function to create popups.
function hs_newPopup(name,text) {
	if (style) document.writeln('<div id="'+name+'_popup" class="hs-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>');
} 

// Function to create no popup.
function hs_noPopup(name,text) {
	if (style) document.writeln('<div id="'+name+'_popup" class="hs-table"></div>');
} 

// Function to create icons.
function hs_newMouseIcon(name,filename) {
	if (style) document.writeln('<div id="'+name+'_icon" class="hs-icon"><img src="'+filename+'"></div>');
} 

// Error message if popups are not available yet.
hs_newPopup("hs_wait",'<TR><TD class="hs-tt1">No link information available yet. Please wait...</TD></TR>');
// If icon is not available...
//hs_newMouseIcon("hs_no",'http://_hyperscout.scone.de/res/colors/blank.gif');
