
/*** Array to hold the original onMouseOver event handlers ***/
var saved_onOver = new Array();
/*** Function pointer to hold the current onMouseOut event handler ***/
var the_onOut;
var hovrLayr;
var ow;
/***
*
* Function   : startHover
*              
* This is the initialisation. It saves all
* existing onMouseOver event handlers and then
* redirects all onMouseOvers for non blank
* text links to hvr_on().
*/
function startHover()
{
	if(document.layers)
	{
		hovrLayr=new Layer(300);
		findAllLinks(document,0,0);
	}
}

function ns4SetStyle(trg,str)
{
   
if (document.layers)
	with (document.tags.A)
	{
		eval(str);
	}
		
}

/**
* locates all links in the document.
* 	d - a document object
* 	x - the x coord of the parent layer
* 	y - the y coord of the parent layer
**/

function findAllLinks(d,x,y)
{
	var i ;// create local variable

	for(i=0 ; i<d.links.length ; i++)
		if(d.links[i].text != null)
		{
			var lnk = d.links[i];
			/*** If the link already has a mousover - save it ***/
			if(lnk.onmouseover != null)
			{
				//alert (lnk.onmouseover);
				saved_onOver[hashStr(lnk)] = lnk.onmouseover;
			}
				
			lnk.onmouseover=hvr_on;
			lnk.sx = x + lnk.x;
			lnk.sy = y + lnk.y;
         }

	for(i=0 ; i<d.layers.length ; i++)
	{
		/*** recursively find any nested layers ***/
		findAllLinks(d.layers[i].document,d.layers[i].pageX,d.layers[i].pageY);
	}

}
/**
* Creates a unique reference to a link by
* using the link x,y co-ordinates and the
* link text.
* 	lnk - A link OBJECT
**/
function hashStr(lnk)
{
	return("onM" + lnk.x + "_" + lnk.y + "_" + lnk.text);
}

/**
* Description : The difficult bit. Puts an exact copy of the
*               link (including onMouseOver/Out/Click) into
*               the layer named "hovr", moves the layer to
*               the exact co-ordinates of the link text and
*               overlays the link with the new layer.
* evt - Standard Netscape event object.
**/

function hvr_on(evt)
{

		
	var obj=evt.target;
	var hash_it = hashStr(obj);
    var hovr_txt = "<A HREF=\"" + obj.href + "\"";
	if(obj.target)
		hovr_txt += (" TARGET=\"" + obj.target + "\"");
	hovr_txt += (" onMouseOut=\"hvr_off()\">" +obj.text+ "</A>");
	
	with (document.tags.A)
	{
		nsb_color = color;
		nsb_backgroundColor = backgroundColor;
		nsb_textDecoration = textDecoration
		nsb_fontWeight     = fontWeight
		nsb_fontStyle      = fontStyle
		nsb_fontSize       = fontSize
	}
	
	if (window.ns4Hover) window.ns4Hover();
	if (saved_onOver[hash_it] && saved_onOver[hash_it].toString().search(/ns4SetStyle/) >=0 )
	{
		//evt.target = hovrLayr;
		saved_onOver[hash_it](hovrLayr);
	}

	hovrLayr.document.open();
	hovrLayr.document.write(hovr_txt);
	hovrLayr.document.close();
	
	with (document.tags.A)
	{
		color = nsb_color;
		backgroundColor = nsb_backgroundColor;
		textDecoration = nsb_textDecoration
		fontWeight     = nsb_fontWeight
		fontStyle      = nsb_fontStyle
		fontSize       = nsb_fontSize
		
	}
	hovrLayr.left=obj.sx;
	hovrLayr.top =obj.sy;
	if (!saved_onOver[hash_it] ||  saved_onOver[hash_it].toString().search(/ns4SetStyle/) < 0 )
		hovrLayr.document.links[0].onmouseover = saved_onOver[hash_it];
	hovrLayr.document.links[0].onclick = obj.onclick;
	hovrLayr.visibility = "show";
	the_onOut=obj.onmouseout;
}

/**
* turns off the hover layer and executes the
* onMouseOut event handler. 
* 		evt - Standard Netscape event object.
*
**/

function hvr_off()
{
	hovrLayr.visibility = "hide";
	if(the_onOut)
		(the_onOut)(); /*** WOW, just like 'C'. Execute a pointer to a function. ***/
}
