Horizontal subnav with Css & Jquery, need help

hi all,

I’m working on designing my first website and i implemented a horizontal subnav, which i got the code for here: http://www.sohtanaka.com/web-design/horizontal-sub-nav-with-css-jquery/

I have two questions, the more important one, how would i make an “active class” so that the subnav would be open when one of the main links is active?

example: click on link 1 => go to link 1 page and sublink 1, 2, 3 are visible.

If you could help me out i would be very grateful.

Also, in the link provided above, there is a section where there is a script which contains the explanation for which Jquery actions are being performed.
How would i go about implementing it to my site? just add the code to the header section? or make an external js file?
the script:

<script type=“text/javascript”>
$(document).ready(function() {

$("ul#topnav li").hover(function() { //Hover over event on list item
	$(this).css({ 'background' : '#1376c9 url(topnav_active.gif) repeat-x'}); //Add background color and image on hovered list item
	$(this).find("span").show(); //Show the subnav
} , function() { //on hover out...
	$(this).css({ 'background' : 'none'}); //Ditch the background
	$(this).find("span").hide(); //Hide the subnav
});

});
</script>

Cheers and thanks in advance :slight_smile: