/*	Copyright (c) 1996,2001 Picdar Technology Limited       All Rights Reserved
 *
 * 	This is UNPUBLISHED PROPRIETARY work of Picdar Technology Limited;
 * 	the contents of this file may not be disclosed to third parties, copied or
 * 	duplicated in any form, in whole or in part, without the prior written
 * 	permission of Picdar Technology Limited
 *
 *	Module   :	Menus.js
 *
 *	Synopsis :	Scripts to control showing and hiding floating box menus
 *
 *	Author   :	Matt Searle
 *
 */

/* 	REQUIRES:
		- Browser.js
*/

MENU_CurrentlyShowing = null;

/*	Get a style element from IE
 */
function IEStyl(element)
	{
	return document.all.tags("div")[element].style;
	}

/*	Get a style element from Netscape
 */
function NSStyl(element)
	{
	return FindElement(element, 0);
	}

/*	Find a style element in Netscape
 */
function FindElement(element, layer)
	{
	if (GetBrowserVersion() < 4)
		return document[element];
	
	var curDoc = layer ? layer.document : document;
	var elem = curDoc[element];
	if (!elem)
		{
		for (var i = 0; i < curDoc.layers.length; i++)
			{
			elem = FindElement(element, curDoc.layers[i]);
			if (elem)
				return elem;
			}
		}
	return elem;
	}

/*	Hides the currently displayed thingy
 */
function HideForIEOnPC()
	{
	if (MENU_CurrentlyShowing != null && IsUsingPC() && IsUsingIE())
		{
		SetStyleVis(MENU_CurrentlyShowing, 0);
		MENU_CurrentlyShowing = null;
		}

	return ClickReturn();
	}

/*	Set the visibility element of a style
 */
function SetStyleVis(element, v)
	{
	if (IsUsingIE())
		IEStyl(element).visibility = (v == 0) ? "hidden" : "visible";
	else
		NSStyl(element).visibility = (v == 0) ? 'hide' : 'show';
	}

/*	Get the visibility element of a style
 */
function GetStyleVis(element)
	{
	if (IsUsingIE())
		return (IEStyl(element).visibility == "hidden") ? 0 : 1;
	else
		return (NSStyl(element).visibility == 'hide') ? 0 : 1;
	}

/*	Show, hide or toggle the visibility of a style
 */
function ShowHide(element, action)
	{
	if (element == '')
		return ClickReturn();
	
	if (MENU_CurrentlyShowing != null && MENU_CurrentlyShowing != element)
		SetStyleVis(MENU_CurrentlyShowing, 0);
	MENU_CurrentlyShowing = element;
	
	if (action == 'hide')
		SetStyleVis(element, 0);
	else if (action == 'show')
		SetStyleVis(element, 1);
	else if (action == 'toggle')
		{ 
		if (GetStyleVis(element) == 0)
			SetStyleVis(element, 1);
		else
			SetStyleVis(element, 0);
		}
	
	return ClickReturn();
	}

