Can't load Fancybox from inside a jQuery script...

Can't load Fancybox from inside a jQuery script...

So I have a script that retrieves images from Flickr and displays them on my site. I have Fancybox so that when a user clicks on the image, the picture will come up in a... "fancy box"... everything seems correct, but when I click on the image, it sends the user to the location of the picture on Flickr servers instead of opening it using Fancybox.

I'm pretty new to web design, so I'm very stumped. Here is the code for the Flickr retrieving...

  1. <script type="text/javascript">
  2. var FLICKR_ID = '41313008@N08';
  3. var THUMBNAIL_HTML = '<a id="single" href="%IMAGE_URL%" title="%IMAGE_TITLE%"><img alt="%IMAGE_TITLE%" src="%THUMBNAIL_URL%" /></a>';
  4.     
  5. function displayImages(data)
  6. {
  7. var htmlString = "";
  8.        
  9. $.each(data.items, function(i,item){
  10. var thumbnail = (item.media.m).replace("_m.jpg", "_s.jpg");
  11. var large = (item.media.m).replace("_m.jpg", ".jpg");
  12. htmlString += THUMBNAIL_HTML;
  13. htmlString = htmlString.replace(/%IMAGE_TITLE%/g, item.title);
  14. htmlString = htmlString.replace(/%IMAGE_URL%/g, large);
  15. htmlString = htmlString.replace(/%THUMBNAIL_URL%/g, thumbnail);
  16. });
  17.        
  18. $('#gallery').html(htmlString);
  19. }
  20.     
  21. $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=44608353@N07&lang=en-us&format=json&jsoncallback=?", displayImages);
  22. </script>

<a id="single" is the id that goes to open the image in Fancybox. When I disable this Flickr script, and input an image manually, it works 100%.

Thank you so so much.