/*******************************************************************
*
* File    : hover.js
*
* Created : 1999/11/02
*
* Author  : Roy Whittle  (Roy@Whittle.com)
*
* Purpose : To simulate the onMouseOver text color change of IE.
*
* History
*
* Date         Version        Description
* 1999-11-02    1.0           First Version It works! amazing.
* 1999-12-29    1.1           Moved font colour/selection to outside script.
* 2000-05-06    1.2		Dynamically create the layer using new Layer();
*******************************************************************/
/*** 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
*              
* Description : 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);
		for(i=0 ; i<document.links.length ; i++)
			if(document.links[i].text != null)
			{
				if(document.links[i].onmouseover != null)
					save_it(document.links[i]);

				document.links[i].onmouseover=hvr_on;
			}

		ow = outerWidth;
		window.captureEvents(Event.RESIZE);
		window.onresize=handle_resize;
	}

}/***********************************************************
* Function   : save_it
*
* Parameters : obj - A link OBJECT
*              
* Description : Creates a unique reference to a link by
*               using the link x,y co-ordinates and then
*               stores the onMouseOver default action for
*               that link.
***********************************************************/
function save_it(obj)
{
	var hash_it = "onM" + obj.x + "_" + obj.y;

	saved_onOver[hash_it] = obj.onmouseover;
}
/***********************************************************
* Function   : hvr_on
*
* Parameters : evt - Standard Netscape event object.
*              
* 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.
*
***********************************************************/
function hvr_on(evt)
{
	var obj=evt.target;
	var hash_it = "onM" + obj.x + "_" + obj.y;

	var hovr_txt = "<A HREF=\"" + obj.href + "\"";

	if(obj.target)
		hovr_txt += (" TARGET=\"" + obj.target + "\"");
	hovr_txt += (" onMouseOut=\"hvr_off()\">" +obj.text+ "</A>");
	hovrLayr.document.open();
	hovrLayr.document.write(hovr_txt);
	hovrLayr.document.close();
	hovrLayr.left=obj.x;
	hovrLayr.top =obj.y;
	hovrLayr.document.links[0].onmouseover = saved_onOver[hash_it];
	hovrLayr.document.links[0].onclick     = obj.onclick;
	hovrLayr.visibility = "show";

	the_onOut=obj.onmouseout;
}
/***********************************************************
* Function   : hvr_off
*
* Parameters : evt - Standard Netscape event object.
*              
* Description : turns off the hover layer and executes the
*               onMouseOut event handler. 
*
***********************************************************/
function hvr_off()
{
	hovrLayr.visibility = "hide";
	if(the_onOut)
		(the_onOut)(); /*** WOW, just like 'C'. Execute a pointer to a function. ***/
}
function handle_resize()
{
//alert("ow = " + outerWidth);
//alert("oh = " + outerHeight);
	if(outerWidth != ow)
	{
		ow = outerWidth;
		location.reload();
	}
	return false;
}