﻿//Barry Fogarty 1 August 2009
//Function loads a Flickr Set in JSON format via an API call.  Appends each photo to the 's-show' element.
//Calls the 'cycle' function of the jcycle plugin.
function flickrCycle(setId) {
    //Call the Flickr feed via the jQuery getJSON method:
    $.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=" + setId + "&nsid=41105740@N08&lang=en-us&format=json&jsoncallback=?",
	function(data) {

	    $.each(data.items, function(i, item) {
	        $("<img />").attr({
	            src: item.media.m.replace('_m.jpg', '.jpg'),
	            title: item.title,
	            alt: item.title,
	            width: '500',
	            height: '298',
	        }).appendTo("#s-show"); //.wrap("<a href='" + item.link + "' target=\"_blank\"></a>")

	    });

	    //jCycle call
	    $('#s-show').cycle({
	        fx: 'fade',
	        speed: 1000,
	        timeout: 5000,
	        next: '#next',
	        prev: '#prev',
	        after: onAfter
	    });

	});

    return false;
}

//Callback function to show the image title in the 's-show-caption' element
function onAfter() {
   $('#s-show-caption').html(this.title);
}
