

//create api object
api =
{
	url: "http://api.flickr.com/services/rest/?jsoncallback=?",
	//?jsoncallback=? is to set up anonymous function
	key: "9e7a6e0586f1df11fb31cac41c7c0666"

};



var photosetRequest = $.ajax({
	url:api.url,
	dataType: 'jsonp',
	data: {
		photoset_id: "72157643067829604",
		format: 'json',
		api_key: api.key,
		method: "flickr.photosets.getPhotos"
	}

});
//when the request is done do this
photosetRequest.done(function(response)
{
	var photos = response.photoset.photo;
	// console.log(photos)

	//once have photoset now need individual ids
	$.each(photos, function(index,photo)
	{
		// console.log(photo.id)
		var photoRequest = $.ajax({
			url:api.url,
			dataType: 'jsonp',
			data: {
				photo_id: photo.id,
				format: 'json',
				api_key: api.key,
				method: "flickr.photos.getSizes"
			}

		});

		photoRequest.done(function(response){
			// console.log(response)
			// console.log(response.sizes.size[5].source)
			var imageSource = response.sizes.size[5].source;
			// var imgTag = $('<img/>');
			var imgTag = '<a class="col-2 pad10All galleryPic" href="'+imageSource+'" target="_blank"><img src="'+imageSource+'" alt="'+photo.title+'" rel="group" class="fancybox"></a>';
			// imgTag.attr({
			// 	src: imageSource,
			// 	alt: photo.title,
			// 	class: 'col-2 margin5All fancybox',
			// 	rel:'group'
			// });
			$('#text').append(imgTag);
			// imgTag.appendTo('#work .row');
		});
	});
});

//if know name of wrapped object
// var jsonFlickrApi = function(response)
// {
// 	console.log("from flickr!", response)
// }
