// ******************************************************************* //
// SCRIPT: Main code for the handling of the dynamic navigation menu   //
//         Positioning is handled in the "dynamicMenu.css" StyleSheet  //
// *** INITIALIZE **************************************************** //
// Initialize Menu Categories
var Number     = 5; 
// Initialize Timers
var current    = 1000;
var timer1     = null, timer2=null, time=100;
// *** FUNCTION: Browser Sniffer ************************************* //
function checkBrowser() {
	this.opera = (navigator.userAgent.indexOf('Opera')>-1);
	this.ie4   = (document.all && !document.getElementById);
	this.ie5   = (document.all && document.getElementById && !this.opera);
	this.ns4   = (document.layers && !document.getElementById);
	this.ns6   = (!document.all && document.getElementById && !this.opera);
	this.mac   = (navigator.userAgent.indexOf('Mac')>-1 && this.ie4);
	this.ok    = (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.opera);
}
br = new checkBrowser()
// *** FIX: IE4 Timing Issue ***************************************** //
if (br.ie4) time = 700;
// *** FIX: Netscape 4 Resize Issue ********************************** //
if (br.ns4) {
	scrollX  = innerWidth;
	scrollY  = innerHeight;
	onResize = function() {
		if (scrollX != innerWidth || scrollY != innerHeight) {
			history.go(0);
		}
	}
}
// *** FUNCTION: Menu Maker ****************************************** //
function makeMenu(obj,nest) {
	nest        = (!nest)?'':'document.'+nest+'.';
	this.el     = br.ie4?document.all[obj]:br.ns4?eval(nest+'document.'+obj):document.getElementById(obj);
	this.css    = br.ns4?this.el:this.el.style;
	this.x      = (br.ns4||br.opera)?this.css.left:this.el.offsetLeft;
	this.y      = (br.ns4||br.opera)?this.css.top:this.el.offsetTop;
	this.width  = (br.ie4||br.ie5||br.ns6)?this.el.offsetWidth:br.ns4?this.el.clip.width:br.opera?this.css.pixelWidth:0;
	this.height = (br.ie4||br.ie5||br.ns6)?this.el.offsetHeight:br.ns4?this.el.clip.height:br.opera?this.css.pixelHeight:0;
	this.moveTo = menuPosition;
	this.hideIt = menuHide;
	this.showIt = menuShow;
}
// *** FUNCTIONS: Show/Hide Object Methods *************************** //
function menuPosition(x,y) {
	this.x        = x;
	this.y        = y;
	this.css.left = x;
	this.css.top  = y;
}
function menuHide() {
	this.css.visibility = 'hidden';
}
function menuShow() {
	this.css.visibility = 'visible';
}
function show(num) {
	clearTimeout(timer1);
	clearTimeout(timer2);
	if (current != num) hideCurrent();
	subMenu[num].showIt();
	current = num;
	if (br.ns4) setTimeout('clearTimeout(timer2)',time/2);
}
function hideCurrent() {
	if (current != 1000) subMenu[current].hideIt();
}
// *** FUNCTION: Initialize Menu ************************************ //
function initializeMenu() {
	finalMenu = new makeMenu('menuDiv');
	mainMenu = new Array();
	for (var i = 0; i < Number; i++) {
		mainMenu[i] = new makeMenu('mainMenu' + i);
		mainMenu[i].el.onmouseout = function() {
			timer1 = setTimeout('hideCurrent()',time);
		}
	}
	subMenu = new Array();
	for(var i = 0; i < Number; i++) {
		subMenu[i] = new makeMenu('subMenu'+i);
		subMenu[i].el.onmouseover = function() {
			clearTimeout(timer1);
			clearTimeout(timer2);
		}
		subMenu[i].el.onmouseout  = function() {
			timer2 = setTimeout('hideCurrent()',time);
		}
	}
	finalMenu.showIt();
	for (var i = 0; i < Number; i++) mainMenu[i].showIt();
}
// *** CHECK: If everything checks out, Initialize Menu ************** //
if (br.ok) {
	initializeMenu();
}
