;(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) {
					$('<img src="' + item.media.m + '" border="0" id="g' + i + '" style="position:absolute;display:none">').appendTo(container);
					num_images++;
				});
				$.nextPhoto();
			});
		}

		$.nextPhoto = function() {
			$("#g" + counter).fadeOut(op.speed);

			counter++
			if(counter >= num_images)
				counter = 0;
			$("#g" + counter).fadeIn(op.speed);

			timer = setTimeout(function () {
				$.nextPhoto();
			}, op.interval*500);
		}

		if(!op.speed) op.speed = "slow";

		$.requestPhoto();
	}
})(jQuery);
