$(document).ready(function() {
	loadFlickr("41237400@N08","springsummer09collection");
});

function addLB(tag) {
	$('#'+tag+' a').lightBox();
}

function loadFlickr(flickrid,tag)
{
	// Display a loading icon in our display element
	$('#'+tag+'').html('<span><img src="images/lightbox-ico-loading.gif" /></span>');

	// Request the JSON and process it
	$.ajax({
		type:'GET',
		url:"http://api.flickr.com/services/feeds/photos_public.gne",
		data:"id="+flickrid+"&tags="+tag+"&lang=en-us&format=json&jsoncallback=?",
		success:function(feed) {
			// Create an empty array to store images
			var thumbs = [];

			// Loop through the items
			for(var i=0, l=feed.items.length; i < l; ++i) 
			{
				// Manipulate the image to get thumb and medium sizes
				if(i > 5)
				{
					var img = feed.items[i].media.m.replace(
						/^(.*?)_m\.jpg$/, 
						'<a class="hidden" href="$1.jpg"><img src="$1_s.jpg" alt="Spring Summer 09 Collection" /></a>'
					);
				} else {
					var img = feed.items[i].media.m.replace(
						/^(.*?)_m\.jpg$/, 
						'<a href="$1.jpg"><img src="$1_s.jpg" alt="" /></a>'
					);
				};

				// Add the new element to the array
				thumbs.push(img);
			}

			// Display the thumbnails on the page
			$('#'+tag+'').html(thumbs.join(''));

			// A function to add a lightbox effect
			addLB(tag);
		},
		dataType:'jsonp'
	});
}