$(function () {
	runBuild = function(){		
		$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&photoset_id=72157623079549809&api_key=bac98938ea7b72ddf906c5cdedb83879&format=json&jsoncallback=?&extras=url_m",	  
		function(data){
    	$.each(data.photoset.photo, function(i,item){                                         
			$("<img />").attr({
			    src: item.url_m.replace("_m.jpg", ".jpg"),
			    title: item.title,
			    alt: item.title
				}).appendTo("#images");
			$("<h3>").html(item.title).addClass("title" + i).appendTo("#images");	
			//
			$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&photo_id=" + item.id + "&api_key=bac98938ea7b72ddf906c5cdedb83879&format=json&jsoncallback=?",	  
			function(data){
    			$("<p>").html(data.photo.description._content).insertAfter("#images h3.title" + i);
			});
			//
			$("<img />").attr({
			    src: item.url_m.replace("_m.jpg", "_t.jpg"),
			    title: item.title,
			    alt: item.title
				}).appendTo("#thumbs").wrap("<div><a href=\"#\" id=\"goto" + i + "\"></a></div>");
			$('#thumbs img').jcaption();
			$('#goto' + i).click(function() { 
				$('#images').cycle(i); 
			return false; 
		});
		});      
		$("#images img").each(function(){
   			var $this = $(this);
  			$this.add($this.next()).wrapAll('<div class="slide"></div>')
		}); 
		$("#thumbs div:nth-child(2n)").after('<br style="clear:both"/>');
		$('#images').cycle({
      		fx: 'fade',
       		speed: 'normal',
       		timeout: 0,
       		next: '#next',
       		prev: '#prev'
		});
	});
		return false;
	}	
	$(function(){
		runBuild();
	});	
});