//**************************************************************************************************
// DYNAMIC SIDE MENU - The menu is produced by RxCMS and ALL menu items are intially visible.  This 
// script collapses the menu items and then drills down to the selected item and expands menus		
// accordingly.																						
//**************************************************************************************************

function dynamicSideMenu()
{
	var sideMenuCollection = document.getElementById("sideMenu").getElementsByTagName("DIV");
	var arrMenuItemSelected;
	var blnMenuItemSelected = false;
	var strMenuItemSelected = "";
	var intLevel = 0;
	var intLevelOne = 0;
	var i = 0;
	var x = 0;
	var y = 0;

	if(sideMenuCollection.length > 0)
		{
		// First, Hide all Menu Items at Level 2 or higher
		for(i = 0; i < sideMenuCollection.length; i++)
		{
			if(sideMenuCollection[i].id.substring(sideMenuCollection[i].id.length-1,sideMenuCollection[i].id.length) > 1)
			{
				document.getElementById("" + sideMenuCollection[i].id + "").style.visibility = "hidden";
				document.getElementById("" + sideMenuCollection[i].id + "").style.display = "none";
			}
		}

		// Second, Loop through the Side Menu collection and determine which item is selected, if any
		for(i = 0; i < sideMenuCollection.length; i++)
		{
			if(sideMenuCollection[i].id.indexOf("aspSelected") > -1)
			{
				blnMenuItemSelected = true;
				intLevel = sideMenuCollection[i].id.substring(sideMenuCollection[i].id.length-1,sideMenuCollection[i].id.length);
				strMenuItemSelected = sideMenuCollection[i].id.toString();
				break;
			}
		}

		// Third, if any menu item at Level 1 or greater is selected, drill to that item and display
		// all child items of the Selected Menu Item
		if(blnMenuItemSelected && intLevel > 0)
		{
			// Search Level 1 Menu Items
			for(i = 0; i < sideMenuCollection.length; i++)	
			{
				if(sideMenuCollection[i].id.substring(sideMenuCollection[i].id.length-1,sideMenuCollection[i].id.length) == 1)
				{
					arrMenuItemSelected = strMenuItemSelected.split("/");
					arrMenuItem = sideMenuCollection[i].id.split("/");			
					
					// If Level 1 Match Found
					if(arrMenuItem[2] == arrMenuItemSelected[2])
					{
						intLevelOne = i;
					
						// Display all Level 2 items if any
						for(x = 0; x < sideMenuCollection.length; x++)
						{					
							if(sideMenuCollection[x].id.indexOf("/" + arrMenuItemSelected[1] + "/" + arrMenuItemSelected[2] + "/") > -1 && 
								sideMenuCollection[x].id.substring(sideMenuCollection[x].id.length-1,sideMenuCollection[x].id.length) == 2)
							{						
								document.getElementById("" + sideMenuCollection[x].id + "").style.visibility = "visible";
								document.getElementById("" + sideMenuCollection[x].id + "").style.display = "block";
							}
						}
						// If SelectedItem is Level 2 or 3
						if(intLevel > 1)
						{
							// Change the style of the Level 1 item to match, Levels 2 and 3
							// This matches Wachovia's Menu functionality
							document.getElementById("" + sideMenuCollection[intLevelOne].id + "").style.cssClass = "sideMenuBar2";
							
							for(y = 0; y < sideMenuCollection.length; y++)
							{					
								if(sideMenuCollection[y].id.indexOf("/" + arrMenuItemSelected[1] + "/" + arrMenuItemSelected[2] + "/" + arrMenuItemSelected[3] + "/") > -1)
								{
									document.getElementById("" + sideMenuCollection[y].id + "").style.visibility = "visible";
									document.getElementById("" + sideMenuCollection[y].id + "").style.display = "block";
								}
							}
						}
						break;
					}
				}
			}
		}
	}
}