jQuery not closing my popup on click

jQuery not closing my popup on click

Hi All

I am testing a Popup window using jQuery but I am not able close it. Can any one help me in closing this popup. 
This my HTML Code
  1. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
  2. <script>
  3. $(document).ready(function() {
  4. //Put in the DIV id you want to display
  5. launchWindow('#dialog1');
  6. //if close button is clicked
  7. $('.window #close').click(function () {
  8. $('#mask').hide();
  9. $('.window').hide();
  10. });
  11. //if mask is clicked
  12. $('#mask').click(function () {
  13. $(this).hide();
  14. $('.window').hide();
  15. });
  16. $(window).resize(function () {
  17.   var box = $('#boxes .window');
  18.         //Get the screen height and width
  19.         var maskHeight = $(document).height();
  20.         var maskWidth = $(window).width();
  21.         //Set height and width to mask to fill up the whole screen
  22.         $('#mask').css({'width':maskWidth,'height':maskHeight});
  23.         //Get the window height and width
  24.         var winH = $(window).height();
  25.         var winW = $(window).width();
  26.         //Set the popup window to center
  27.         box.css('top',  winH/2 - box.height()/2);
  28.         box.css('left', winW/2 - box.width()/2);
  29. });
  30. });

  31. function launchWindow(id) {
  32. //Get the screen height and width
  33. var maskHeight = $(document).height();
  34. var maskWidth = $(window).width();
  35. //Set heigth and width to mask to fill up the whole screen
  36. $('#mask').css({'width':maskWidth,'height':maskHeight});
  37. //transition effect
  38. $('#mask').fadeIn(1000);
  39. $('#mask').fadeTo("slow",0.8);
  40. //Get the window height and width
  41. var winH = $(window).height();
  42. var winW = $(window).width();
  43. //Set the popup window to center
  44. $(id).css('top',  winH/2-$(id).height());
  45. $(id).css('left', winW/2-$(id).width()/2);
  46. //transition effect
  47. $(id).fadeIn(2000); 
  48. }
  49. </script>

  50. </head>

  51. <body>
  52. <!-- Start of Login Dialog -->  
  53. <div id="boxes">
  54. <div id="dialog1" class="window">
  55. <div class="d-header">
  56.         <div style="padding-top:50px;padding-left:115px;">
  57.         <img src="jquery-modal-window-queness/images/dapl-representative-small.jpg" width="151" height="100" />
  58.         </div>
  59.   <input type="text" value="Enter Phone No." onclick="this.value=''"/><br/>
  60.   <input type="text" value="Enter eMail ID" onclick="this.value=''"/>  <br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  61.             <font color="#FF9F38">Please give us your details and our representative will contact with you.</font>
  62.   </div>
  63. <input type="image" alt="Close" title="Close" src="jquery-modal-window-queness/images/x.png" class="close"/>
  64. </div>
  65. </div>    
  66. <div id="mask"></div>
  67. <!-- End of Login Dialog -->  

Now When I click on on the masked area Pop disappear but when I click on the image x.png Popup doesn't go away.
I need some hint or guidance.

Thank you all.