//
// +----------------------------------------------------------------------+
// | Sitellite - Content Management System                                |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 Simian Systems                                    |
// +----------------------------------------------------------------------+
// | This software is released under the Simian Open Software License.    |
// | Please see the accompanying file OPENLICENSE for licensing details!  |
// |                                                                      |
// | You should have received a copy of the Simian Open Software License  |
// | along with this program; if not, write to Simian Systems,            |
// | 101-314 Broadway, Winnipeg, MB, R3C 0S7, CANADA.  The Simian         |
// | Public License is also available at the following web site           |
// | address: <http://www.simian.ca/license.php>                          |
// +----------------------------------------------------------------------+
// | Authors: John Luxford <lux@simian.ca>                                |
// | Modified:                                                            |
// |   2002-04-10 / R.Balmforth / To resolve stuck menus problem, removed |
// |                mouseTracker for menu hiding and replaced with event  |
// |                functions mouseEnterMenu and mouseExitMenu which are  |
// |                called by the menu item onmouseover event and         |
// |                onmouseout respectively. Clearing menus is acheived   |
// |                by a timer to 'debounce', that triggers               |
// |                the new function checkShowOrHide.                     |
// +----------------------------------------------------------------------+
//
// This provides a lightweight show and hide facility that can be used to
// create (among other things) simple DHTML drop menus.
//
// Browser Compatibility:
// - NS6/Mozilla - no known issues
// - IE5/6 - no known issues
// - NS4 - only issue: menus don't like to disappear when you mouse off
//         their edges.
// - Others - untested
//
// Note: There is some code at the bottom that pertains to the following
// copyright notice:
//
/*
============================================================
Capturing The Mouse Position in IE4-6 & NS4-6
(C) 2000 www.CodeLifter.com
Free for all users, but leave in this  header
*/

// requires javascript 1.2 or greater

// requires a dom sniffer that defines doc and vis as globals, such as this
var doc;
var vis;

// crappy dom sniffing
if (document.getElementById) {
	doc = 'document.getElementById ("';
	vis = '").style';
} else if (document.all) {
	doc = 'document.all["';
	vis = '"].style';
} else if (document.layers) {
	doc = 'document.layers["';
	vis = '"]';
}

// show a drop menu layer
function show (obj) {
	try {
		eval (doc + obj + vis + '.visibility = "visible"');
	} catch(e){}; 
}

// hide a drop menu layer
function hide () {
	for (i = 0; i < arguments.length; i++) {
		try {
			eval (doc + arguments[i] + vis + '.visibility = "hidden"');
		} catch(e){};
	}
}

// show this list, and hide all other menu layers
// (requires a globally defined list of menu layer
// names called menuList)
function showAndHide () {
	try {
		list:
		for (i = 0; i < menuList.length; i++) {
			for (j = 0; j < arguments.length; j++) {
				if (menuList[i] == arguments[j]) {
					eval (doc + menuList[i] + vis + '.visibility = "visible"');
					continue list;
				}
			}
			eval (doc + menuList[i] + vis + '.visibility = "hidden"');
		}

	} catch(e){};
}

// checks to see if the mouse has left the area of a particular menu,
// and closes it, as well as all of its children
function mouseTracker (name, x1, y1, x2, y2) {
	if (! (tempX >= x1 && tempX <= x2 && tempY >= y1 && tempY <= y2)) {
		showAndHide ();
	}
	return true;
}

/*
============================================================
Capturing The Mouse Position in IE4-6 & NS4-6
(C) 2000 www.CodeLifter.com
Free for all users, but leave in this  header
*/

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
// rjb removed - not required now, hits performance
// document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
	try {
		if (IE) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX;
			tempY = e.pageY;
		}

		// catch possible negative values in NS4
		if (tempX < 0){tempX = 0}
		if (tempY < 0){tempY = 0}  

		return true;
	} catch(e){};
}


//
// RJB Additional Techland functions here
//

function mouseEnterMenu()
{
	// called when the mouse enters a menu item
	// ensure that menu is not cleared by resetting flag
	try {
		hideMenus = false;	
		return true;
	} catch(e){};
}

function mouseExitMenu()
{
	// called on mouseout of a menu item
	// (re)set timer to clear menus and flag that the mouse has moved out!
	try {
		hideMenus = true;

		// clear timer if set	
		if (timerID != 0) 
		{
			clearTimeout(timerID);
		}

		timerID = setTimeout("checkShowOrHide()", 1000);
	
		return true;
	} catch(e){};
}

// this function called on timer expiry, will check flag to see if menus need closing
var timerID = 0;
var hideMenus = false;

function checkShowOrHide()
{
	try {
		if(timerID)
		{
			clearTimeout(timerID);
			timerID = 0;
		}

		// if menu is still flagged to be hidden then hide it
		if (hideMenus)
		{
			hideMenus = false;
			showAndHide();
		}

		return true;
	} catch(e){};
}

