I have the following menu in my masterpage:
This should NOT be done with Javascript! Deciding which page you are on is the job of the server side code, it's not a UI behaviour.
Have the menu as a user control and pass a value to it to indicate which part of the menu should be highlighted. I'm front end person, not a .NET developer but something like this: