addClass and removeClass works but changes are not seen by jQuery functions.

addClass and removeClass works but changes are not seen by jQuery functions.

Hello!

I'm building a gallery and i have a couple of thumbnails.
There is always 1 active thumbnail (opacity 100%) of the showing image and several inactive thumbnails (opacity 50%).

I've build some functions to catch clicks for those functions:

  1.     $(document).ready(function() {
  2. $(".galleryinactivethumb").click(function(){
  3. $(".galleryactivethumb").removeClass('galleryactivethumb').addClass('galleryinactivethumb');
  4. $(this).removeClass('galleryinactivethumb').addClass('galleryactivethumb');
  5. alert("inactive thumb clicked!");
  6. return;
  7. });
  8. $(".galleryactivethumb").click(function(){
  9. alert("active thumb clicked!");
  10. return;
  11. });
  12. jQuery('.galleryinactivethumb').each(function() {
  13.             $(this).hover(function() {
  14. //Hover out
  15.                 $(this).stop().animate({ opacity: 1.0 }, 500)
  16.             },
  17.            function() {
  18.   //Hover on
  19.   $(this).stop().animate({ opacity: 0.5 }, 500);
  20.                ;
  21.            });
  22.   
  23.         });
When i click an inactive thumb the classes are changes to the correct classes (safari/chrome's webinspector shows the change in the classes) but when i then click the same thumb again it run's the function of the previous class(witch was removed jus a second ago).

Am i doing something wrong here?

I can't get it to work!

Can someone help me with this?

Thanks!