;(function($) {
	$.fn.gallery = function(op) {
		var container = $(this);
		var image = container.children("img");
		var counter = -1;
		var timer;
		var timeout_timer;
		var num_images = 0;
		var timestamp = new Date();  //we'll use a timestamp on the end of the images to trick IE's cache

		$.requestPhoto = function() {
			$.getJSON(op.file, function(data) {
				$.each(data.items, function(i, item) {
					$('<a style="position:absolute;" href="' + item.link + '" rel="group" class="lightbox" title="' + item.description + '"><img src="' + item.media.m + '" border="0" id="g' + i + '" style="display:none;"></a>').appendTo(container);

					$('a.lightbox').fancybox({
						'zoomSpeedIn'			: 600,
						'zoomSpeedOut'			: 500,
						'easingIn'				: 'easeOutBack',
						'easingOut'				: 'easeInBack'
					});

					num_images++;
				});
				$.nextPhoto();
			});
		}

		$.nextPhoto = function() {
			$("#g" + counter).fadeOut(op.speed);

			counter++
			if(counter >= num_images)
				counter = 0;
			$("#g" + counter).fadeIn(op.speed);

			if(num_images > 1) {
				timer = setTimeout(function () {
					$.nextPhoto();
				}, op.interval*1000);
			}
		}

		if(!op.speed) op.speed = "slow";

		$.requestPhoto();
	}
})(jQuery);