It would be a bit difficult for me to explain exactly how it works (efficiently), but I'll try to answer your questions as best I can.
In the "upper world", the script will take the x/y coordinates of the player and warp the player accordingly to an underwater map. The same is true for the underwater map. So the coordinates of where you can dive from on one map must match up with the coordinates of where you can resurface from underwater on another map.
Oh yeah, and dive/emerge are their own separate scripts.
I have made use of one of JPAN's specials to make it work properly. Special 0x7F - get tile attribute. Hard to explain, but by checking whether or not a certain tile has water encounter potential I can make it work. I should also mention that the dive/emerge script is activated using JPAN's behavior byte hack.
Hope that helps you understand somewhat!