Get the full URL path:
Next split the segments of the URL using:
Finally select the segment you require using:
The above code would select
segment_1 but you can see how you can easily select
Once these segments are stored in variables it is really easy to set states for your navigation using jQuery.
The complete code is shown below and I have posted the example for you to use and modify as you see fit over at github.