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

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 < 18; ++i) 
			{
				// Manipulate the image to get thumb and medium sizes
				var img = feed.items[i].media.m.replace(
					/^(.*?)_m\.jpg$/, 
					'<a href="$1.jpg"><img src="$1_s.jpg" alt="'+tag+'" /></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'
	});
}
