Problem using jquery.fancybox first picture showing twice

Problem using jquery.fancybox first picture showing twice

Hello,

Im having problem using jquery.fancybox.
The problem is, when loading main page for the first time gallery is displaying first image twice, here is some code :
  1. <script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
  2. <script type="text/javascript">

  3. $(document).ready(function() {
  4. //Execute the slideShow
  5. slideShow();

  6. });

  7. function slideShow() {

  8. //Set the opacity of all images to 0
  9. $('#gallery a').css({opacity: 0.0});
  10. //Get the first image and display it (set it to full opacity)
  11. $('#gallery a:first').css({opacity: 1.0});
  12. //Set the caption background to semi-transparent
  13. $('#gallery .caption').css({opacity: 0.7});

  14. //Resize the width of the caption according to the image width
  15. $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
  16. //Get the caption of the first image from REL attribute and display it
  17. $('#gallery .cont').html($('#gallery a:first').find('img').attr('rel'))
  18. .animate({opacity: 0.7}, 400);
  19. //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
  20. setInterval('gallery()',5000);
  21. }

  22. function gallery() {
  23. //if no IMGs have the show class, grab the first image
  24. var current = ($('#gallery a.show') ?  $('#gallery a.show') : $('#gallery a:first'));

  25. //Get next image, if it reached the end of the slideshow, rotate it back to the first image
  26. var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));
  27. //Get next image caption
  28. var caption = next.find('img').attr('rel');
  29. //Set the fade in effect for the next image, show class has higher z-index
  30. next.css({opacity: 0.0})
  31. .addClass('show')
  32. .animate({opacity: 1.0}, 1000);

  33. //Hide the current image
  34. current.animate({opacity: 0.0}, 1000)
  35. .removeClass('show');
  36. //Set the opacity to 0 and height to 1px
  37. $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
  38. //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
  39. $('#gallery .caption').animate({opacity: 0.7},10 ).animate({height: '60px'},500 );
  40. //Display the cont
  41. $('#gallery .cont').html(caption);
  42. }

  43. </script>
  44. <style type="text/css">

  45. .clear {
  46. clear:both;
  47. }

  48. #gallery {
  49. position:relative;
  50. height:360px;
  51. }
  52. #gallery a {
  53. float:left;
  54. position:absolute;
  55. }
  56. #gallery a img {
  57. border:none;
  58. }
  59. #gallery a.show {
  60. z-index:500;
  61. }

  62. #gallery .caption {
  63. z-index:600; 
  64. background-color:#000; 
  65. color:#ffffff; 
  66. height:60px; 
  67. width:100%; 
  68. position:absolute;
  69. bottom:0;
  70. }

  71. #gallery .caption .cont {
  72. margin:5px;
  73. }
  74. #gallery .caption .cont h3 {
  75. margin:0;
  76. padding:0;
  77. color:#1DCCEF;
  78. }
  79. </style>
  80. <?php
  81. $con = mysql_connect("localhost","xxx","xxx");
  82. if (!$con)
  83.   {
  84.   die('Could not connect: ' . mysql_error());
  85.   }

  86. mysql_select_db("xxx", $con);
  87. $result = mysql_query("SELECT * FROM xxx");
  88. ?>
  89. <div id="gallery">
  90. <?php
  91. while ($row = mysql_fetch_array($result)) {
  92. ?>
  93. <a href="opis.php?nr=<?php echo $row['nr']; ?>" >
  94. <img src="admin/<?php echo $row['url_zdjecia'] ?>" alt="Zdjecie" width="580" height="360" title="" rel="Marka: <?php echo $row['marka']; ?> Model: <?php echo $row['model']; ?><br>Rok produkcji: <?php echo $row['rok_produkcji']; ?> Pojemnosc: <?php echo $row['silnik']; ?> <br>Cena: <?php echo number_format($row['cena'], 0, ',', ' ')." PLN"; ?>"/>
  95. </a>

  96. <?php
  97. }
  98. ?>
  99. <div class="caption"><div class="cont"></div></div>
  100. </div>

  101. <script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
  102. <script type="text/javascript">

  103. $(document).ready(function() {
  104. //Execute the slideShow
  105. slideShow();

  106. });

  107. function slideShow() {

  108. //Set the opacity of all images to 0
  109. $('#gallery a').css({opacity: 0.0});
  110. //Get the first image and display it (set it to full opacity)
  111. $('#gallery a:first').css({opacity: 1.0});
  112. //Set the caption background to semi-transparent
  113. $('#gallery .caption').css({opacity: 0.7});

  114. //Resize the width of the caption according to the image width
  115. $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
  116. //Get the caption of the first image from REL attribute and display it
  117. $('#gallery .cont').html($('#gallery a:first').find('img').attr('rel'))
  118. .animate({opacity: 0.7}, 400);
  119. //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
  120. setInterval('gallery()',5000);
  121. }

  122. function gallery() {
  123. //if no IMGs have the show class, grab the first image
  124. var current = ($('#gallery a.show') ?  $('#gallery a.show') : $('#gallery a:first'));

  125. //Get next image, if it reached the end of the slideshow, rotate it back to the first image
  126. var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));
  127. //Get next image caption
  128. var caption = next.find('img').attr('rel');
  129. //Set the fade in effect for the next image, show class has higher z-index
  130. next.css({opacity: 0.0})
  131. .addClass('show')
  132. .animate({opacity: 1.0}, 1000);

  133. //Hide the current image
  134. current.animate({opacity: 0.0}, 1000)
  135. .removeClass('show');
  136. //Set the opacity to 0 and height to 1px
  137. $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
  138. //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
  139. $('#gallery .caption').animate({opacity: 0.7},10 ).animate({height: '60px'},500 );
  140. //Display the cont
  141. $('#gallery .cont').html(caption);
  142. }

  143. </script>
  144. <style type="text/css">

  145. .clear {
  146. clear:both;
  147. }

  148. #gallery {
  149. position:relative;
  150. height:360px;
  151. }
  152. #gallery a {
  153. float:left;
  154. position:absolute;
  155. }
  156. #gallery a img {
  157. border:none;
  158. }
  159. #gallery a.show {
  160. z-index:500;
  161. }

  162. #gallery .caption {
  163. z-index:600; 
  164. background-color:#000; 
  165. color:#ffffff; 
  166. height:60px; 
  167. width:100%; 
  168. position:absolute;
  169. bottom:0;
  170. }

  171. #gallery .caption .cont {
  172. margin:5px;
  173. }
  174. #gallery .caption .cont h3 {
  175. margin:0;
  176. padding:0;
  177. color:#1DCCEF;
  178. }
  179. </style>
  180. <?php
  181. $con = mysql_connect("localhost","xxx","xxx");
  182. if (!$con)
  183.   {
  184.   die('Could not connect: ' . mysql_error());
  185.   }

  186. mysql_select_db("xxx", $con);
  187. $result = mysql_query("SELECT * FROM xxx");
  188. ?>
  189. <div id="gallery">
  190. <?php
  191. while ($row = mysql_fetch_array($result)) {
  192. ?>
  193. <a href="opis.php?nr=<?php echo $row['nr']; ?>" >
  194. <img src="admin/<?php echo $row['url_zdjecia'] ?>" alt="Zdjecie" width="580" height="360" title="" rel="Marka: <?php echo $row['marka']; ?> Model: <?php echo $row['model']; ?><br>Rok produkcji: <?php echo $row['rok_produkcji']; ?> Pojemnosc: <?php echo $row['silnik']; ?> <br>Cena: <?php echo number_format($row['cena'], 0, ',', ' ')." PLN"; ?>"/>
  195. </a>

  196. <?php
  197. }
  198. ?>
  199. <div class="caption"><div class="cont"></div></div>
  200. </div>