Fancybox (Lightbox) - Last image not working.

Fancybox (Lightbox) - Last image not working.

Hi all

I have this simple gallery that loads images from an xml file and
uses  Fancybox to display the images.


Everything is working but the last image is not working with fancybox. The
last image just displays in it's own window.

Can anyone see why the last image is not displaying with fancybox.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  7.  
  8.     <title>untitled</title>
  9.     <link rel="stylesheet" href="style.css" type="text/css">
  10.     <link rel="stylesheet" href="fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
  11. </head>
  12.  
  13. <body>
  14.   <div class="wrap">
  15.     <div id="header"><ul></ul></div>  
  16.     <div id="content"></div>
  17.   </div>
  18.   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"type="text/javascript"></script>
  19.   <script type="text/javascript" src="fancybox/jquery.fancybox-1.3.4.pack.js"></script>
  20. <script type="text/javascript" src="fancybox/jquery.easing-1.4.pack.js"></script>
  21.   <script type="text/javascript">
  22.           
  23.     function slideContent(div){
  24.       var $content = $('#content');
  25.       var divPos = $('#content ' + div).position();
  26.       var scrollPosition = $content.scrollTop()+divPos.top;
  27.       $('#content').animate({scrollTop: scrollPosition}, 500);
  28.     }
  29.                
  30.     $.ajax({
  31.       type: 'GET',
  32.       url: 'images.xml',
  33.       dataType: 'xml',
  34.       success: function(xml){
  35.         $(xml).find('section').each(function(){
  36.           var id = $(this).attr('id');
  37.           var secName = $(this).attr('secName');
  38.           var divName = '#'+secName;
  39.           var nav_onClick = "slideContent('" + divName + "')";
  40.           var link = '<a href="#" onclick="' + nav_onClick + '">' +secName+ '</a>';
  41.           $('<li></li>').html(link).appendTo('#header ul');
  42.           $('<div id='+secName+' class="section"><ul></ul></div>').appendTo('#content');         
  43.             $(this).find('img').each(function(){
  44.               var thumb = $(this).attr('imgName')+'_th.jpg'; 
  45.               var img = $(this).attr('imgName')+'.jpg';   
  46.               var img_onClick = $('.single_image').fancybox(); 
  47.               var imgLink = '<a href="'+img+'" onclick="'+img_onClick+'" class="single_image" ><img src="'+thumb+'" /></a>';
  48.               $('<li></li>').html(imgLink).appendTo('#'+secName+' ul');
  49.               //
  50.             })
  51.         });
  52.       }
  53.     })
  54.          
  55.   </script>
  56. </body>
  57. </html>