The negative z value on the second map is because I need the fog to show above a parallax.
Okay, that took a bit of searching, but it's got something to do with this ^^^.
I temporarily changed the script to ignore the z value passed in, and the fog displayed correctly on the first map after battling on the third. So I removed that change, and changed the show_fog command on the first map to use fog/picture 2 rather than 1 (so there wouldn't be any remnant of the -1 value around), and it also worked.
So there's something about the negative z value, the battle on the third map, and redisplaying the fog using the same array position/id without passing in a z value - maybe it retains what was there before. But that doesn't explain why leaving the map and returning, or going into a menu and exiting, fixes it.
As a workaround, you could change the "inner" area to use #2 instead of #1 (on the assumption that this is the only fog you have set to a negative z value and would be easier to change this than go through and find all the others). But I'll continue to look and see if I can find the exact cause.
Out of interest, the fog doesn't seem to be displaying during the battle in the "inner" area. It may be that giving it a negative z value is placing it behind the battle background. This may have something to do with the issue as well. Should the fog be visible during this battle?
You also have two events showing the fog on the first map - the one is in the top left corner on that map. The other is the exit event from the cave map - it also shows the fog just after the transfer command. It's probably not necessary - I removed it to see if it might have any effect, and the fog still displayed okay.
The other thing I discovered is that it's repeatedly going to the cache for the fog on every frame, and not only when a new one is loaded. This is inefficient, and might cause a little bit of lag. I don't know why I wrote it that way, unless it's just that that's what the XP fog script did so I duplicated the logic without thinking too hard about it. When I have time, I'll make a mod to the script and you can grab the updated version.