var arrImages = [];

function jsonFlickrApi(rsp)
{
	if (rsp.stat != "ok")
	{
		// If this executes, something broke!
		return;
	}
	
	//this loop runs through every image and creates image objects
	for (var i=0; i < rsp.photoset.photo.length; i++)
	{
		photo = rsp.photoset.photo[ i ];
		
		t_url = "http://farm" + photo.farm
			+ ".static.flickr.com/" + photo.server + "/"
			+ photo.id + "_" + photo.secret + ".jpg";
			
		p_url = "http://www.flickr.com/photos/"
			+ photo.owner + "/" + photo.id;
		
		p_obj = new Object();
		p_obj.src = t_url;
		p_obj.href = p_url;
		p_obj.target = '_blank';
		arrImages[arrImages.length] = p_obj;
	}
}

	jQuery(function($)
	{
		$(document).ready(function()
		{
			/*
			$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=37027090@N08&lang=en-us&format=json&jsoncallback=?", function(data)
			{
				$.each(data.items, function(i,item)
				{
					flickrImage = new Object();
					flickrImage.src = item.media.m.replace("_m.jpg", ".jpg");
					flickrImage.href = item.link;
					flickrImage.target = '_blank';
					arrImages[arrImages.length] = flickrImage;
				});
			});
			*/

			shuffle = function(o)
			{ //v1.0
				for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
				return o;
			};

			// set default gallery image while we wait for the others to load
			var rndImg = Math.floor(Math.random() * arrImages.length);
			$('#custom_box').css('background-image', 'url(' + arrImages[rndImg].src + ')' );
			$('#custom_box').css('background-repeat', 'no-repeat');
			$('#custom_box').css('background-position', 'center');

			$('#custom_box').crossSlide(
				{sleep: 20, fade: 1.5, resize: true}, shuffle(arrImages));
		});
	});