Button to images using jquery?

Button to images using jquery?

Hi,

Small problem with button clicking...

 #button1 says "red colour" and #button2 is a button that says "blue colour" and it should display to whatever colour depending on what button you press. ATM it will display if you click red and then blue but you cant then re-click red, or if you do it blue and then red it wount work if you then click on red.

Any idea's where i am going wrong ( hope you understand) Thanks

  1.  $(document).ready(function(){
  2. var margin =$("#image2").height()/2;
  3. var height=$("#image2").height();
  4. var width=$("#image2").width();
  5. var margin =$("#image7").height()/2;
  6. var height=$("#image7").height();
  7. var width=$("#image7").width();
  8. $("#image2").stop().css({height:'0px',width:''+width+'px',marginTop:''+margin+'px',opacity:'0.5'});
  9. $("#image7").stop().css({height:'0px',width:''+width+'px',marginTop:''+margin+'px',opacity:'0.5'});


  10. $("#button1").click(function(){
  11. window.setTimeout(function() {
  12. $("#image2").stop().animate({height:''+height+'px',width:''+width+'px',marginTop:'0px',opacity:'1'},{duration:500});
  13. },500);
  14. });

  15. $("#button2").click(function(){
  16. window.setTimeout(function() {
  17. $("#image7").stop().animate({height:''+height+'px',width:''+width+'px',marginTop:'0px',opacity:'1'},{duration:500});
  18. },500);
  19. });