function photos($){
	$("#slides > *").each(function(index, element) {
		var requested_image = $(element);
		var new_circle = $('<span class="slide-circle"></span>');
		
		requested_image.css({display: 'block', position: 'relative'});

		new_circle.click(function(event) {
			if ($(this).hasClass('active')) {
				return;	
			}
			
			$('.slide-circle').removeClass('active');
			$(this).addClass('active');
			var top_static_image = $('#slides > *:not(.moving)').last();
			
			requested_image.insertBefore(top_static_image);
			var clone = top_static_image.clone();
			clone.insertBefore(top_static_image);
			top_static_image.prependTo('#slides');
			clone.addClass('moving');
			clone.animate({left:"950px", opacity:"0"}, 1000, function (){
				$(this).remove();
			});
		});
		
		$('#slide-circles').append(new_circle);
	});
	
	var gotoNextSlide = function() {
		var next_circle = $('.slide-circle.active + .slide-circle');
		if (next_circle.length == 0) {
			next_circle = $('.slide-circle:first-child');	
		}
		next_circle.click();
	};
	
	var slideIntervalId = setInterval(gotoNextSlide, 5000);
	
	$('#slides-play-button').click(function() { clearInterval(slideIntervalId); slideIntervalId = setInterval(gotoNextSlide, 5000); });
	$('#slides-pause-button').click(function() { clearInterval(slideIntervalId); });
}



jQuery(photos);

