Thanks. That mostly does the trick, but the first level menus continue to cover the header in this case and won’t scroll off. There’s a usability issue from this since a lot of the items at the top of each of the first level subs have submenus of their own, making it that a user can’t easily mouse over to the neighbouring top level menu items. Is it possible to keep the submenus below main menu items at the same time?
I figured out what I needed to do; without a guard to skip the whole operation on lower-level submenus I’d end up in a deadly cycle. The solution was to add this as the first line of the event handler:
if ($(menu).parentsUntil('#main-menu').length != 1) return;