$(document).ready(function() {
	runBuild = function(){

		$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=nectardesserts&lang=en-us&format=json&jsoncallback=?",
    		function(data){
    		  if (data.items.length < 1) return false;
    		  	$.each(data.items, function(i,item){
    				$("<img />").attr({
    				    src: item.media.m,
    				    title: item.title,
    				    alt: item.title
    				}).appendTo("#images").wrap("<a href='" + item.link + "' target=\"_blank\"></a>");

    				$("#title").html(data.title);
    				$("#description").html(data.description);
    				$("#photoset").html("<a href='"+data.link+"' target=\"_blank\" class=\"underlined\">See All Flickr Images tagged with  nectardesserts</a>");

    			});

    			$('#images').cycle({
          	fx:     'fade',
            speed:    'normal',
            timeout:  0,
            next:   '#next',
            prev:   '#prev'
    			});

          $('#flickrContain').show('fast');
    		});

		return false;
	}

	$(function(){
		if ($('#flickrContain').length == 1) runBuild();
		$('#refreshLink').click(runBuild);
	});

});


