glow.ready(function() {
  if (glow.dom.get('#carousel-container').length != 0) {
  	glow.net.loadScript("http://api.flickr.com/services/feeds/photos_faves.gne?id=31216459@N07&lang=en-us&format=rss_200&format=json&jsoncallback={callback}", {
  	 onLoad: function(data) {
  	  glow.dom.get('#carousel-container').html(' ');
      if (data.items.length > 0) {
  				glow.dom.create('<ul id="carousel-flickr"></ul>').appendTo('#carousel-container');
          for(i=0; i<6; i++) {
  					src = glow.lang.replace(data.items[i].media.m, /m\.jpg/, "s.jpg");
  					link = data.items[i].link;
  					title = data.items[i].title;
  					author = data.items[i].author;
  					var start = author.lastIndexOf('(')+1;
  					var end = author.lastIndexOf(')');
  					author = author.substring(start, end);
  					glow.dom.create('<li class="flickr-img-box flickr-img-box-'+i+'"><div class="inner-box"><a href="' + link + '"><img class="flickr-img" src="'+src+'" alt="Springwatch Flickr group" border="0" /></a></div></li>').appendTo('#carousel-flickr');				
  				}
    
          flickrCarousel = new Carousel('#carousel-flickr',   
                                   {  
                                       visibleItems : 3
                                   });  
  
          glow.dom.get('#carousel-flickr').before("<a id='previous' href='javascript:flickrCarousel.move(1)'><span>previous</span></a>");  
          glow.dom.get('#carousel-flickr').after("<a id='next' href='javascript:flickrCarousel.move(-1)'><span>next</span></a>");    
  
      } else {glow.dom.get('#carousel-container').html('<p>Currently there are no images.</p>')}
  	}
    });
  }
});