/////////////////////////////////////////////////////////////////////////////
//	menuBar
//
//	menuBar.js
//
//	Copyright 2000-2002 Isotools, all rights reserved
//	This document is company confidential and the whole property
//	of Isotools.
//
/////////////////////////////////////////////////////////////////////////////
//
//	DESCRIPTION :
//	-----------
//
//	The menuBar object define the "popup menus" used in some sites designed 
//	by Isotools products.
//
//	This menuBar is intended to work with the following browsers :
//		- IE 4.x
//		- IE 5.x
//		- NS 4.x
//		- NS 6
//
//	IE6 NOTES : 
//	---------
//	As IE 6 is intended to be standard compliant (just use the correct 
//	doctype declaration) the menuBar has many chances to work with IE 6
//	As far, no test has been done with IE6
//
/////////////////////////////////////////////////////////////////////////////
//
//	Last update: March 6, 2002.
//
/////////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------
//
//	Used to track all navigation bars.
//
var menuBars = new Array();
//
//	variables to create layer's ID.
//
var menuBarIndex = 0;
var itemGroupIndex = 0;
var itemIndex = 0;
//
//	variable used for NS6, to create layers inside the menuBar
//	main layer
//
var mainLayerElement = null;
//-----------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////
//	
//	MenuBar Object
//	--------------
//	
//	It defines the navigation bar and its dropdown menus.
//	It designed to be "full customizable" so the following may be changed 
//	by user :
//		- position 
//		- orientation
//
//	The MenuBar object gathers all those information and a reference to 
//	its child itemGroup object which is the first level menu
//
//	MenuBar must have an image to position it named "menuPlaceHolder" 
//	suffixed with the index of the menu (in the menuBars Array), which is
//	also used to reposition menus at browser resize.
//
///////////////////////////////////////////////////////////////////////////
function MenuBar(width, height)
{
	// position and orientation (vertical or horizontal)
	this.x = 0;
	this.y = 0;
	this.orientation = "horizontal"; // possible value : "horizontal" or "vertical"

	// size
	this.width	= width;
	this.height	= height;

	// children
	this.childGroup = null;
	
	// status
	this.created = false;

	// Add to the list.
	this.index = menuBars.length;
	menuBars[this.index] = this;
}

MenuBar.prototype.setChildGroup = function (itemGroup)
{
	this.childGroup = itemGroup;
	itemGroup.parentItem = null;
	itemGroup.menuBar = this;
}

MenuBar.prototype.setOrientation = function (orientation)
{
	this.orientation = orientation;
}

MenuBar.prototype.setPosition = function (x, y)
{
	this.x = x;
	this.y = y;
}

MenuBar.prototype.create = function (){return false;}
MenuBar.prototype.moveTo = function (x, y){return false;}
MenuBar.prototype.setzIndex = function (z){return false;}
///////////////////////////////////////////////////////////////////////////
// END MENUBAR OBJECT
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//	
//	ItemGroup Object
//	----------------
//	
//	It defines a dropdown menu in the menu bar.
//	It designed to be "full customizable" so the following may be changed 
//	by user :
//		- colors
//		- fonts
//		- size
//		- decoration	(use of escape method is required)
//		- next			(use of escape method is required)
//
//	The ItemGroup object gathers all those informations and array of the menu 
//	items it contains.
//
///////////////////////////////////////////////////////////////////////////

// to easily reteive groups by layerID
var allItemGroups = new Array();

function ItemGroup(width, height)
{
	// size
	this.width  = width;
	this.height = height;

	// default sizes.
	this.border    = 1;
	this.padding   = 4;
	this.separator = 1;

	// colors.
	this.borderColor= "#000000";
	this.fgColor	= "#000000";
	this.bgColor	= "#ffffff";
	this.hiFgColor	= "#ffffff";
	this.hiBgColor	= "#666666";

	// font.
	this.fontFamily			= "Verdana, Arial,Helvetica,sans-serif";
	this.fontWeight			= "bold";
	this.fontSize			= "10pt";
	this.textDecoration		= "none";
	this.hiTextDecoration	= "underline";

	this.orientation = "";

	this.index = -1;

	// img to display when child items have dropdown menu
	this.nextImg	= "";
	this.hiNextImg	= "";

	// decoration (it means HTML which be included before each item of the group)
	this.decoration = "";
	this.hiDecoration = "";

	// parent
	this.parentItem = null;
	this.menuBar	= null;

	// children
	this.items = new Array();
}

ItemGroup.prototype.setSizes = function(border, padding, separator)
{
	this.border    = border;
	this.padding   = padding;
	this.separator = separator;
}

ItemGroup.prototype.setColors = function(borderColor, fgColor, bgColor, hiFgColor, hiBgColor)
{
	this.borderColor= borderColor;
	this.fgColor	= fgColor;
	this.bgColor	= bgColor;
	this.hiFgColor	= hiFgColor;
	this.hiBgColor	= hiBgColor;
}

ItemGroup.prototype.setFonts = function(fontFamily, fontWeight, fontSize, textDecoration, hiTextDecoration)
{
	this.fontFamily			= fontFamily;
	this.fontWeight			= fontWeight;
	this.fontSize			= fontSize;
	this.textDecoration		= textDecoration;
	this.hiTextDecoration	= hiTextDecoration;
}

ItemGroup.prototype.setDecoration = function(decoration, hiDecoration, nextImg, hiNextImg)
{
	this.decoration = decoration;
	this.hiDecoration = hiDecoration;
	this.nextImg = nextImg;
	this.hiNextImg = hiNextImg;
}

ItemGroup.prototype.addItem = function(item)
{
	this.items[this.items.length] = item;
	item.parentGroup = this;
}

ItemGroup.prototype.create = function(orientation){return false;}
ItemGroup.prototype.init = function(){return false;}
ItemGroup.prototype.moveBy = function (dx, dy){return false;}
ItemGroup.prototype.setzIndex = function (z){return false;}
ItemGroup.prototype.isMouseOver = function (mouseX, mouseY){return false;}
///////////////////////////////////////////////////////////////////////////
// END ITEMGROUP OBJECT
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//	
//	Item Object
//	------------
//	
//	It defines an item of the menu bar
//	The information needed to create an item are :
//		- text				(use of escape method is required)
//		- click action		(use of escape method is required)
//		- mouseOver action	(use of escape method is required)
//		- mouseOut action	(use of escape method is required)
//
//	As the menuBar can be as deep as we want, each item may have a 
//	reference to an itemGroup object, which will define a sub menu.
//
///////////////////////////////////////////////////////////////////////////
function Item(text, click, mouseOver, mouseOut)
{
	// content
	this.text = text;	// Item text.

	// actions
	this.click		= click;	// CLICK	: Link URL or JavaScript code.
	this.mouseOver	= mouseOver;// MOUSEOVER: JavaScript code.
	this.mouseOut	= mouseOut;	// MOUSEOUT	: JavaScript code.

	this.index = -1;
	this.parentGroup = null;
	this.childGroup = null;

	// position
	this.top  = 0;
	this.left = 0;

	//isHighlighted
	this.isHighlighted = false;
}

Item.prototype.setChildGroup = function(itemGroup)
{
	this.childGroup = itemGroup;
	itemGroup.parentItem = this;
	itemGroup.menuBar = this.parentGroup.menuBar;
}

Item.prototype.create = function(parentElement){return false;}
Item.prototype.initEvents = function (){return false;}
Item.prototype.resize = function (width, height){return false;}
///////////////////////////////////////////////////////////////////////////
// END ITEM OBJECT
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
// EVENT MANAGEMENT
///////////////////////////////////////////////////////////////////////////
var toHide = new Array();
var isVisible = new Array();
var showTimeOutID = new Array();

function ItemOnMouseOver(e){return false;}
function ItemOnMouseOut(e){return false;}
function ItemClick(e)
{
	var click =  unescape(this.item.click);
	if (click.indexOf("javascript:") == 0)
		eval(click);
	else
		window.location.href = click;
}

function GroupOnMouseOver(e){return false;}
function GroupOnMouseOut(e){return false;}

function hide(){return false;}
function show(group){return false;}
function cancelHide(id){return false;}

///////////////////////////////////////////////////////////////////////////
// Code to handle a window resize.
///////////////////////////////////////////////////////////////////////////

addResizeActions(menuBarReloadAll);

function menuBarReloadAll(){menuBarReload();}

///////////////////////////////////////////////////////////////////////////
// UTILS
///////////////////////////////////////////////////////////////////////////
function getImage(name)
{
	var img = null;

	if (isNS4)
		img = findImage(name, document);
	else if (isIE4)
		img = eval('document.all.' + name);
	else if (isDOM)
		img = document.getElementById(name)

	return img;
}

function findImage(name, doc)
{
	var i, img;

	for (i = 0; i < doc.images.length; i++)
		if (doc.images[i].name == name)
			return doc.images[i];
	for (i = 0; i < doc.layers.length; i++)
		if ((img = findImage(name, doc.layers[i].document)) != null)
		{
			img.container = doc.layers[i];
			return img;
		}
	return null;
}

function getImagePageLeft(img)
{
	var x, obj;

	if (isNS4)
	{
		if (img.container != null)
			return img.container.pageX + img.x;
		else
			return img.x;
	}
	else if (isIE || isDOM)
	{
		x = 0;
		obj = img;
		while (obj.offsetParent != null)
		{
			x += obj.offsetLeft;
			obj = obj.offsetParent;
		}
		x += obj.offsetLeft;
		return x;
	}
	return -1;
}

function getImagePageTop(img)
{
	var y, obj;

	if (isNS4) 
	{
		if (img.container != null)
			return img.container.pageY + img.y;
		else
			return img.y;
	}
	else if (isIE || isDOM) 
	{
		y = 0;
		obj = img;
		while (obj.offsetParent != null) 
		{
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
		y += obj.offsetTop;
		return y;
	}

	return -1;
}

//-----------------------------------------------------------------
// select correct file (depends of browser loading the page)
//-----------------------------------------------------------------
var ua = window.navigator.userAgent.toLowerCase();
var i = 0;
var version = 0;
if ((i = ua.indexOf('msie')) != -1)
	version  = parseFloat('0' + ua.substr(i+5), 10);

var isNS6 = ((typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isDOM = (document.getElementById) ? true : false;
var isIE  = (document.all) ? true : false;
var isIE5 = (isIE)&&(version >= 5) ? true : false;
var isIE4 = (isIE)&&(version < 5) ? true : false;
var isMAC = (window.navigator.platform.toLowerCase().indexOf('mac') != -1)?true:false;

var browserFile = (isNS4) ? "ns4" : ((isNS6) ? "ns6" : ((isIE5) ? "ie5" : "ie4"));

if (isNS4 || isNS6 || isIE4)
{
	document.write("<SCR" + "IPT SRC='./iso_misc/ua.js' TYPE='text/javascript'><\/SCR" + "IPT>");
	document.write("<SCR" + "IPT SRC='./iso_misc/xbstyle_lib.js' TYPE='text/javascript'><\/SCR" + "IPT>");
}

document.write("<SCR" + "IPT SRC='./iso_misc/menubar_"+ browserFile +".js' TYPE='text/javascript'><\/SCR" + "IPT>");

///////////////////////////////////////////////////////////////////////////
// ------------------------ End of File -----------------------------------
///////////////////////////////////////////////////////////////////////////

