/**
 * Author: Gary Chin
 * Last Update: Aug 18, 2002
 * Copyright (c) 2002 RangeWave Inc.
 */

//var imgSubSubMenuPath = 'images/subsubmenu/';

var NS = (document.layers ? true:false);
var hideContent = (NS ? 'hide':'hidden');
var showContent = (NS ? 'show':'visible');


var subSubMenus;
var imgSubSubMenuOn = new Array();
var imgSubSubMenuOff = new Array();

var obj;
var preIndex;
var calledValue = 0;  // Used for testing statment to overcome an IE onMouseOut bug
var curPos = 0;  // Keeps track of the starting index position of each id

//------------------------------------------- Initialization --------------------------------------------//
/**
 * Initialization function for preloading images etc
 ***************************************************/
function initialize()
{
	subSubMenus = new Array(new subSubMenu('corp', 3), new subSubMenu('network', 3), new subSubMenu('partner', 3),
				new subSubMenu('inetserv', 3), new subSubMenu('dataserv', 3), new subSubMenu('voiceserv', 2));
				//new subSubMenu('proserv', 3));
}

//-------------------------------- Sub Sub Menu Initialization Routines ---------------------------------//
/**
 * Contains the pop-up menu (sub sub menu) information
 *****************************************************/
function subSubMenu(id, numOfOpts)
{
	this.name = id;
	this.totalOpts = numOfOpts;
	this.startIndex = curPos;
	curPos += numOfOpts;
	if (numOfOpts != 0) preLoadSubSubMenuImg(id, numOfOpts);
}

/**
 * Preloads the pop-up menu images
 *********************************/
function preLoadSubSubMenuImg(id, numOfOpts)
{
var imgSubSubMenuPath = '/images/subsubmenu/';
	for (var i = 1; i <= numOfOpts; i++)
	{
		imgSubSubMenuOn[imgSubSubMenuOn.length] = new Image();
		imgSubSubMenuOn[imgSubSubMenuOn.length - 1].src = imgSubSubMenuPath + "subsub_" + id + i + "_on.jpg";
		imgSubSubMenuOff[imgSubSubMenuOff.length] = new Image();
		imgSubSubMenuOff[imgSubSubMenuOff.length - 1].src = imgSubSubMenuPath + "subsub_" + id + i + "_off.jpg";
	}
}

/**
 * Show the pop-up menu of the id
 ********************************/
function showSubSubMenu(id)
{
	if (NS)
	{
		if (id)
		{
			var newY = window.pageYOffset;

			document.menutrapper.top = newY;
			document.menutrapper.visibility = "visible";

			eval("document." + id + ".top = " + newY);
			eval("document." + id + ".visibility = 'visible'");

			preIndex = findIndex(id);
		}
	}
	else
	{
		if (id)
		{
			var mtObj = document.getElementById("menutrapper");
			obj = document.getElementById(id);

			// Re-adjust the y position to display the pop-up menu correctly
			if (parseInt(navigator.appVersion) >= 5)  // NS
			{
				var newY = window.pageYOffset;
				mtObj.style.top = newY;
				obj.style.top = newY;
			}
			else  // IE
			{
				var newY = document.body.scrollTop;
				mtObj.style.pixelTop = newY;
				obj.style.pixelTop = newY;
			}

			mtObj.style.visibility = "visible";
			obj.style.visibility = "visible";
			preIndex = findIndex(id);
		}
	}
}

/**
 * Hide the pop-up menu of the id
 ********************************/
function hideSubSubMenu(id)
{
	if (NS)
	{
		if (preIndex >= 0)
		{
			eval("document." + subSubMenus[preIndex].name + ".visibility = 'hidden'");
			parent.frames[1].swapOff();
		}
		if (id)
		{
			eval("document." + id + ".visibility = 'hidden'");
		}
		document.menutrapper.visibility = "hidden";
		preIndex = index;
//alert("here2");
	}
	else
	{
//		if (calledValue != 0)
//		{
//alert("3");
//alert(preIndex);
			// This is to work around an IE bug in onMouseOut to hide previous sub sub menu
			// also used in menutrapper
			if (preIndex >= 0)
			{
//alert("here");
				obj = document.getElementById(subSubMenus[preIndex].name);
				obj.style.visibility = "hidden";
				parent.frames[1].swapOff();  // swap pre id img to off
			}
			if (id)
			{
//alert("here2");
				var index = findIndex(id);
				obj = document.getElementById(subSubMenus[index].name);
				obj.style.visibility = "hidden";
			}

			obj = document.getElementById("menutrapper");
			obj.style.visibility = "hidden";
			preIndex = index;
//		}
//		else {//alert("4");
//showSubSubMenu(id);}
	}
//	eval("document.all." + subSubMenus[index].name + ".style.visibility = 'hidden'");
//	contentFrameObj.document.all.id.style.visibility = "hidden";
//	alert("here3");
}

/**
 * Swaps the image in the sub sub menu
 *************************************/
function swapOptImg(underID, imgID, add_index, isOn)
{
//alert(evt);
//	for (var i = 0; i < subSubMenus.length; i++)
//	{
//		if (subSubMenus[i].name == underID)
//		{
			var index = findIndex(underID);
//alert(subSubMenus[i].name + underID);
//alert(subSubMenus[i].startIndex);
//alert(imgSubSubMenuOn[subSubMenus[i].startIndex + index].src);
			if (isOn)
			{
//alert(imgSubSubMenuOn[subSubMenus[index].startIndex + add_index].src);
				if (NS) document.layers[underID].document.images[imgID].src = imgSubSubMenuOn[subSubMenus[index].startIndex + add_index].src;
				else document.images[imgID].src = imgSubSubMenuOn[subSubMenus[index].startIndex + add_index].src;
			}
//				showSubSubMenu(underID);}//alert("on");}
			else
			{
				if (NS) document.layers[underID].document.images[imgID].src = imgSubSubMenuOff[subSubMenus[index].startIndex + add_index].src;
				else document.images[imgID].src = imgSubSubMenuOff[subSubMenus[index].startIndex + add_index].src;
			}
//				hideSubSubMenu(underID);}
//		}
//	}
}

/**
 * Looks for the index of the id
 *******************************/
function findIndex(id)
{
	for (var i = 0; i < subSubMenus.length; i++)
	{
		if (subSubMenus[i].name == id) { return i;}
	}
}