two rotating images fade onclick

two rotating images fade onclick

I have a total of two images. The first image, when click needs to fade into the second image. Then when the second image is clicked it needs to fade back into the first image. This should go on as long the user wishes to click.

Here is my code so far. The first image fade works fine, but I can't get it to fade back to the first image again after loading the second image.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  6. <title>Sandbox</title>
  7. <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  8. </head>
  9. <body>
  10. <img src="rolled-up.png" id="picture" class="up" />
  11. <script type="text/javascript">
  12. $(".up").click(function() {
  13. $(".up").fadeOut("fast",function(){
  14.     $("#picture").load(function () { //avoiding blinking, wait until loaded
  15.         $("#picture").fadeIn();
  16.     });
  17.     $("#picture").attr("src","rolled-down.png");
  18. $("#picture").attr("class","down");
  19. });
  20. });

  21. $(".down").click(function() {
  22. $(".down").fadeOut("fast",function(){
  23.     $("#picture").load(function () { //avoiding blinking, wait until loaded
  24.         $("#picture").fadeIn();
  25.     });
  26.     $("#picture").attr("src","rolled-up.png");
  27. $("#picture").attr("class","up");
  28. });
  29. });
  30. </script>
  31. </body>
  32. </html>
Any idea on how to fully implement this?

Thanks in advance.