/////////////////////////////////////////////////////////
//
//	Copyright (c) 2002-2003 Softpress Systems Ltd.
//	All rights reserved.
//	http://www.softpress.com/
//
/////////////////////////////////////////////////////////

var Opera = navigator.userAgent.indexOf("Opera") != -1;
var version = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("Opera") + 5, navigator.userAgent.length));

function NBSavePosition(obj, layerID)
{
	var layer = FindLayer(layerID);
	
	if (!layer)
		return;

	var obj_l = GetObjectLeft(obj);
	var obj_t = GetObjectTop(obj);
	var obj_w = GetObjectWidth(obj);
	var obj_h = GetObjectHeight(obj);
	
	var obj_r = obj_l + obj_w;
	var obj_b = obj_t + obj_h;

	var lay_l = parseInt(layer.left);
	var lay_t = parseInt(layer.top);
	var lay_w = GetLayerWidth(layerID);
	var lay_h = GetLayerHeight(layerID);
	
	var lay_r = lay_l + lay_w;
	var lay_b = lay_t + lay_h;
	
	// remember current menu
	
	var len = fwActiveMenus.length;
	
	fwActiveMenus[len] = new FWMenu();
	
	fwActiveMenus[len].submenuID = layerID;
	fwActiveMenus[len].itemArea = new FWArea(obj_l, obj_t, obj_r, obj_b);
	fwActiveMenus[len].submenuArea = new FWArea(lay_l, lay_t, lay_r, lay_b);
	fwActiveMenus[len].parentID = "_top";
}

function NBShowMenu(obj, layerID)
{
	if (Opera && version < 6)
		return;
	
	var len = fwActiveMenus.length - 1;
	
	if (len >= 0 && fwActiveMenus[len].submenuID == layerID)
		return;
	
	var layer = FindLayer(layerID);
	
	if (!layer || layer.visibility == "visible" || layer.visibility == "show")
		return;
	
	HideAllMenus();
	
	var left = layer.left ? parseInt(layer.left) : 0;
	var top = layer.top ? parseInt(layer.top) : 0;
	
	if (left == 0 && top == 0)
		SetPosBelow(obj, layer);

	ShowLayer(layerID);
	NBSavePosition(obj, layerID);
}