var arrowImg = new Array();

arrowImg[0] = new Image();
arrowImg[0].src = "images/arrowDown.gif";

arrowImg[1] = new Image();
arrowImg[1].src = "images/arrowSub.gif";

function toggleMenu(parentID, selfID, intMax, intCount, intMaster) {
	var i = 0;
	var obj;
	
	if (parentID == 0) {
		var strName = 'menudiv0-' + selfID;
		
	} else {
		var strName = 'childdiv' + parentID + '-' + selfID;
		
	}
		
	for (i = 0; i < intMax; i ++) {
		strName = 'childdiv' + i + '-' + selfID;	
		obj = document.getElementById(strName);
		
		if (obj != null) {
			if (obj.style.height == '18px') {
				obj.style.height = "0px";
				obj.style.visibility = "hidden";
				obj.style.overflow = "hidden";
								
				// change the arrow image
				var newObj = document.getElementById("menuimg" + selfID + "-" + parentID);
				
				if (newObj != null) {
					newObj.src = arrowImg[1].src;
				}
				
				// check if its a main menu item closing or a child
				// if its a main menu, close all children
				if (parentID == 0) {
					var parentObj = document.getElementById("masterwrapper" + intMaster)
					
					if (parentObj != null) {
						parentObj.style.display = "none";
				
					}
				}
			} else {
				// check if its a main menu item closing or a child
				// if its a main menu, close all children
				if (parentID == 0) {
					var parentObj = document.getElementById("masterwrapper" + intMaster)
					
					if (parentObj != null) {
						parentObj.style.display = "block";
				
					}
				}
				
				obj.style.height = "18px";
				obj.style.visibility = "visible";
				obj.style.overflow = "visible";
								
				// change the arrow image
				var newObj = document.getElementById("menuimg" + selfID + "-" + parentID);
				
				if (newObj != null) {
					newObj.src = arrowImg[0].src;
				}
			}
		}
	}	
}