<!--start of dynamic menu script-->
var menuitems=8;	/* Set this to number of menu items */
function toggle(currentmenuitem)
{
	/*close all open menus, except the current one*/
 	for (i=1;i<=menuitems;i++){
		var menuitem='menuitem'+(i);
  		if (menuitem!=currentmenuitem) { 
			el = document.getElementById(menuitem);
  			el.style.display = 'none';
		}
 	}
	/*toggle the current menu, i.e. open-closed or closed-open*/
	el = document.getElementById(currentmenuitem);
	el.style.display = el.style.display ? '' : 'none';
}
<!--end of dynamic menu script-->