

$(document).ready(function() {


//Flickr homepage JSON feed gallery


	$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=72157626646063050&nsid=62485983@N03&lang=en-us&format=json&jsoncallback=?", function(data){
  
  
		$.each(data.items, function(i,item){

//Pick out Flickr title and description last paragraph data, and store as variables  
			
			var date = item.date_taken.replace(/^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)-08:00$/, function($0, $1, $2, $3){
    			return $3 + "/" + $2 + "/" + $1;
			});

		
			var description = item.description;
			var desc = $("<div />").append(description);
                if ($(desc).children().size() == 3) {
                    desc = $(desc).children("p:last").html();
                } else {
                    desc = "";
                }               

//Add the images and their variables to the div

			$("#flickr").append("<div class='slide'><div class='slide-wrapper'><img src='" + item.media.m.replace(/_m/i, "_z") + "'/><div class='title'><p><span 				class='bold'>" + item.title + "</span><br />" + date + "</p><p>" + desc + "</p></div></div><span class='site-info'><p>&copy; Dennis Tod Interiors | Site by <a href='http://www.digitalpath.co.uk'>Digital Path</a></p></span></div>")
			});
		
			$("#copy").append("<p><span class='bold'>Home</span><br />" + data.description + "</p>");
		
//Use Cycle plugin to rotate the .slide divs	

	  	var opts, startingSlide = 0;
		$('#flickr').cycle({
    		fx:     'fade',
    		speed:    'slow',
    		timeout:  7000,
    		pause:   1,
    		next:   '.next, .slide-wrapper',
    		prev:   '.prev',
    		after:   onAfter,
    		startingSlide: startingSlide
    	}).data('cycle.opts');


	function onAfter(curr,next,opts) {
	var caption = (opts.currSlide + 1) + ' of ' + opts.slideCount;
	$('.caption').html(caption);
	}

    });	


});

