/*
*
*
*/
// ------------------------------------------------------ GLOBALS ---------------------------------------------------------------
var current_menu = '*';	// the menu 'in focus'

//define menus
var menus = new Array();
//menus[[num]] = new Array ([menu name],[menu group],[menu parent(*=top)],[x1],[y1],[x2],[y2]);
menus[0] = new Array ('ddProducts','BASE','*','','','','');

var parent_links = new Array();
//parent_links[[num]] = new Array ([menu name],[x1],[y1],[x2],[y2]);
parent_links[0] = new Array ('ddProducts',428,118,495,138);

// --------------------------------------------- MENU SYSTEM CONTROL FUNCTIONS --------------------------------------------------

//get type of menu from name
function getMenuType(menu_name) {
	var count;
	for (var count=0;count<menus.length;count++) {
		if (menus[count][0] == menu_name) return menus[count][1];
	}
	return false;
}

//get parent menu
function getMenuParent(menu_name) {
	for (var count=0;count<menus.length;count++)
		if (menus[count][0] == menu_name) return menus[count][2];
	return false;
}

//function to set coords of menu
function setMenuCoords(menu_name,absLeft,absTop,absRight,absBottom) {
	//get reference to menu object
	var menuRef; 
	for (var count=0;count<menus.length;count++) 
		if (menus[count][0] == menu_name) menuRef = menus[count]; 
	
	var lyr_bleed = 10; //set layer sensitivity bleed 
	
	//set properties
	menuRef[3] = absLeft - lyr_bleed;
	menuRef[4] = absTop;
	menuRef[5] = absRight + lyr_bleed;
	menuRef[6] = absBottom + lyr_bleed;
	//window.alert('left:' + menuRef[3] + ' top:' + menuRef[4] + 'right:' + menuRef[4] + 'bottom:' + menuRef[6] + '');
}

//get coords of menu
function getMenuCoords(menu_name,coord_type) {

	var coord_pos;

	if (coord_type == "x1") coord_pos = 3;
	if (coord_type == "y1") coord_pos = 4;
	if (coord_type == "x2") coord_pos = 5;
	if (coord_type == "y2") coord_pos = 6;

	for (var count=0;count<menus.length;count++) 
		if (menus[count][0] == menu_name) return menus[count][coord_pos];

	if (current_menu !== "*") alert("get_menucoord:WARNING! COULD NOT FIND " + menu_name + " IN DESCRIPTOR")
}

//get coords of menu parent (not a dd menu)
function getParentCoords(menu_name,coord_type) {

	var coord_pos;

	if (coord_type == "x1") coord_pos = 1;
	if (coord_type == "y1") coord_pos = 2;
	if (coord_type == "x2") coord_pos = 3;
	if (coord_type == "y2") coord_pos = 4;

	for (var count=0;count<menus.length;count++) 
		if (parent_links[count][0] == menu_name) return parent_links[count][coord_pos];

	if (current_menu !== "*") window.alert("get_menucoord:WARNING! COULD NOT FIND " + menu_name + " IN DESCRIPTOR")
}

//loads all menus
function loadMenus () {

	var crntMenu,lyrRef,absLeft,absTop,absRight,absBottom;
	
	for (var i=0;i<menus.length;i++) {
		crntMenu = menus[i];
	
		if (document.layers) {
			lyrRef = eval('document.layers.' + crntMenu[0]);
			absLeft = parseInt(lyrRef.left);
			absTop = parseInt(lyrRef.top);
			absRight = (absLeft + parseInt(lyrRef.clip.right));
			absBottom = (absTop + parseInt(lyrRef.clip.bottom));	
		}
		else {
			if (document.all) lyrRef = eval('document.all.' + crntMenu[0])
			else if (document.getElementById) lyrRef = eval('document.getElementById("' + crntMenu[0] + '")');
			absLeft = parseInt(lyrRef.style.left);
			absTop = parseInt(lyrRef.style.top);
			absRight = (absLeft + parseInt(lyrRef.style.width));
			absBottom = (absTop + parseInt(lyrRef.style.height));	
		}
		setMenuCoords(crntMenu[0],absLeft,absTop,absRight,absBottom);	//set menu coords
		//window.alert ('menu name = ' + crntMenu[0] + '\nmenu group= ' + crntMenu[1] + '\nmenu parent(*=top) = ' + crntMenu[2] + '\nx1= ' + crntMenu[3] + '\ny1= ' + crntMenu[4] + '\nx2 = ' + crntMenu[5] + '\ny2 = ' + crntMenu[6]);
	}
}

 
// --------------------------------------------- MENU ITEM CONTROLS -----------------------------------------------------------

// turn off all members of the specified menus group
function groupOff(input_group) {
	//window.alert('turn off menus in group ' + input_group + ' crnt layer = ' + crntLayer);
	for (var count=0;count<menus.length;count++) {
		if (menus[count][1] == input_group) {
			if (document.all) eval('document.all.' + menus[count][0] + '.style.visibility = "hidden"');
			else if (document.layers) eval('document.layers.' + menus[count][0] + '.visibility = "hide"');
			else if (document.getElementById) eval('document.getElementById("' + menus[count][0] + '").style.visibility = "hidden"');
		}
	}
		
}

//turn all menus off
function allOff() {
	//window.alert('turn off all menus');
	for (var count=0;count<menus.length;count++) {
		if (document.all) eval('document.all.' + menus[count][0] + '.style.visibility = "hidden"');
		else if (document.layers) eval('document.layers.' + menus[count][0] + '.visibility = "hide"');
		else if (document.getElementById) eval('document.getElementById("' + menus[count][0] + '").style.visibility = "hidden"');
	}
}

//activate menu
function activateMenu(menu_name) {

		//window.alert('activate' + menu_name)	
		//deactivate any menus that may be on
		if (getMenuType(menu_name) == 'BASE') allOff();
		else groupOff(getMenuType(menu_name));
		
		if (document.all) {
			eval(menu_name + '.style.visibility = "visible"')
			current_menu = menu_name;
		}
		else if (document.layers) {
			document.layers[menu_name].visibility = 'show';
			current_menu = menu_name;
		}
		else if (document.getElementById) {
			document.getElementById(menu_name).style.visibility = 'visible';
			current_menu = menu_name;
		}
		
}

//deactivate menu
function deactivateMenu(menu_name) {
		//window.alert('deactivate ' + menu_name)	
		if (document.all) {
			eval(menu_name + '.style.visibility = "hidden"')
			current_menu = getMenuParent(menu_name);
		}
		else if (document.layers)	{
			document.layers[menu_name].visibility = 'hide';
			current_menu = getMenuParent(menu_name);
		}
		else if (document.getElementById) {
			document.getElementById(menu_name).style.visibility = 'hidden';
			current_menu = getMenuParent(menu_name);
		}
}

// ------------------------------------------------------------------------------------------------------------------------------

// ---------------------------------------------------- MOUSE MOVEMENT CALUCLATOR -----------------------------------------------

var mx, my;	//global variables to hold mouse coords

function initMonitors () {
	
	if (!document.all) document.captureEvents(Event.MOUSEMOVE) //if not ie then enable mouse event detection 
	document.onmousemove = monitor;	// Set-up to use getMouseXY function onMouseMove
}

// Monitor MOUSE X/Y movement
function monitor(e) {
	
	var name;
	var x;
	var x1,y1,x2,y2;
	var focus_x1, focus_y1, focus_x2, focus_y2;
	var tzone_x1, tzone_y1, tzone_x2, tzone_y2;

	if (document.all) { // grab the x-y pos.s if browser is IE
		mx = event.clientX + document.body.scrollLeft;
		my = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		mx = e.pageX;
		my = e.pageY;
	}

	// catch possible negative values in NS4
	if (mx < 0) mx = 0;
	if (my < 0) my = 0;


	//status = "mx=" + mx + " my=" + my;

	
	if (current_menu !== "*") { //if a menu is active check it
		focus_x1 = getMenuCoords(current_menu,"x1");
		focus_y1 = getMenuCoords(current_menu,"y1");
		focus_x2 = getMenuCoords(current_menu,"x2");
		focus_y2 = getMenuCoords(current_menu,"y2");
		
		// boundary checking without the possibility of a parent
		if ((mx < focus_x1) || (mx > focus_x2) || (my < focus_y1) || (my > focus_y2)) {
			//window.alert('x1 = ' + focus_x1 + ' x2 = ' + focus_x2 + ' y1 = ' + focus_y1 + ' y2 = ' + focus_y2);
			//check that parent link of menu not currently active
			focus_x1 = getParentCoords(current_menu,"x1");
			focus_y1 = getParentCoords(current_menu,"y1");
			focus_x2 = getParentCoords(current_menu,"x2");
			focus_y2 = getParentCoords(current_menu,"y2");
			if ((mx < focus_x1) || (mx > focus_x2) || (my < focus_y1) || (my > focus_y2)) {
				deactivateMenu(current_menu);
			}
		}
	}
	
}
