/////////////////////////////////////////////////////////////////////////////
//	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;
//-----------------------------------------------------------------

var MENUBAR_MAXCHILD = 10;
var MENUBAR_LASTLABEL = "...";
var MENUBAR_SEPARATOR = " ";

///////////////////////////////////////////////////////////////////////////
//	
//	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";
    
    // size
    this.width	= width;
    this.height	= height;

    this.lastItem = null;
    this.length = 0;
	
    // 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 = "";

	this.align = "left";

	this.bgImg = "";
	this.bgImgWidth = 0;
	this.bgImgHeight = 0;

	// parent
	this.parentItem = null;
	this.menuBar	= null;

	// children
	this.items = new Array();
}

ItemGroup.prototype.setTextAlign = function(align) {
    this.align = align;
}

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.setBackground = function(img, width, height) {
    this.bgImg = img;
    this.bgImgWidth = width;
    this.bgImgHeight = height;
}

ItemGroup.prototype.addItem = function(item) {
    var i = this.items.length;
    var bSep = item.isSeparator();
    if (bSep) {
	item.text = MENUBAR_SEPARATOR;
    }
    if (this.menuBar != null && this.menuBar.childGroup == this) {
	var n = this.menuBar.length;
	if (!bSep) {
	    this.menuBar.length++;
	}
	if (n >= MENUBAR_MAXCHILD) {
	    if (this.menuBar.lastItem != null) {
		if (!bSep) {
		    var group = this.menuBar.lastItem.childGroup;
		    group.addItem(item);
		}
	    }
	    else if (bSep) {
		this.items[i] = item;
		item.parentGroup = this;
	    }
	    else {
		var lastItem = new Item(MENUBAR_LASTLABEL,'javascript:','','');
		var group = new ItemGroup(0,0);
		while (i > 0 && this.items[i-1].isSeparator()) {
		    i--;
		    this.items.length = i;
		}
		if (i > 0 && !this.items[i-1].isSeparator()) {
		    this.menuBar.length--;
		    var tmp = this.items[i-1];
		    i--;
		    this.items.length = i;
		    group.addItem(tmp);
		}
		this.items[i] = lastItem;
		lastItem.parentGroup = this;
		this.menuBar.lastItem = lastItem;
		group.addItem(item);
		lastItem.setChildGroup(group);
	    }
	    return;
	}
    }
    this.items[i] = 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
	if (click == "") {
	    mouseOver  = "";
	    mouseOut = "";
        }
	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.isSeparator = function() {
    return this.text == "|" || (this.click == null && (this.childGroup == null || this.childGroup.length == 0));
}

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)
{
    if (this.item.click == null || this.item.click == "") return;
	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 IE6 = false, IE7 = false,
FIREFOX2 = false, FIREFOX = false,
NETSCAPE7 = false, NETSCAPE = false,
OPERA9 = false, OPERA = false,
AUTRE = false;
var strChUserAgent = navigator.userAgent;
var intSplitStart = strChUserAgent.indexOf("(",0);
var intSplitEnd = strChUserAgent.indexOf(")",0);
var strChStart = strChUserAgent.substring(0,intSplitStart);
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
var strChEnd = strChUserAgent.substring(strChEnd);

if(strChMid.indexOf("MSIE 7") != -1)
IE7 = true;
else if(strChMid.indexOf("MSIE 6") != -1)
IE6 = true;
else if(strChEnd.indexOf("Firefox/2") != -1)
FIREFOX2 = true;
else if(strChEnd.indexOf("Firefox") != -1)
FIREFOX = true;
else if(strChEnd.indexOf("Netscape/7") != -1)
NETSCAPE7 = true;
else if(strChEnd.indexOf("Netscape") != -1)
NETSCAPE = true;
else if(strChStart.indexOf("Opera/9") != -1)
OPERA9 = true;
else if(strChStart.indexOf("Opera") != -1)
OPERA = true;
else
AUTRE = true;

var browserFile = (isNS4) ? "ns4" : ((isNS6) ? "ns6" : ((isIE5) ? "ie5" : "ie4"));
if (FIREFOX || FIREFOX2)
  browserFile = "firefox";

if (isNS4 || isNS6 || isIE4 || FIREFOX || FIREFOX2)
{
	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 -----------------------------------
///////////////////////////////////////////////////////////////////////////
