[jQuery] What Do I Do wrong?

[jQuery] What Do I Do wrong?


Hello,
I have the following jQuery code:
$(document).ready(function(){
    $("a.navia:not([id='imprint'])").attr("href", "#");
    $("a.navia").click(function(){
        var active = "div#subnavibg" + $(this).attr("id") + ":hidden";
        $("div.subnavibg:visible").slideUp(500);
        $("a.navia.selected").removeClass("selected");
        $(active).slideDown(500);
        $(this).not([class='selected']).addClass("selected");
        });
});
I think it's quiet clear what the aim of the script is. I have several
navigation links which, when clicked, are to open a sub-navigation
menu.
It works so far except one thing: Everytime I click on a top-
navigation link, this link gets an additional class (selected) just to
change its color to see which navigation link is active. When I click
on another link, the previous active link loses this class and the
clicked link gets this class so that just one navigation link can have
this class (selected).
When I click on the active link the according sub-navigation menu
disappears. So far so good. Nevertheless the class (selected) is not
taken away from the link so that the link stays active for the visitor
though no sub-navigation menu is shown.
I think it's more a logical problem in my head that I'm not able to
solve. Can someone help me with this?
Thank you!
Iustinian