Check array bounds in menu tree before checking whether menu item is in path

The current code generates many non-fatal (but annoying) "Undefined offset" notices. Before checking whether a menu item is in the path, first check whether there is an item at that array index.