jQuery(document).ready(function() {
	jQuery('.slideshow').each(function() {
		var self = this;
	//	Set the pause between slides in seconds.
		var pause = 5;
	//	Set the speed of the animation in seconds.
		var speed = .25;
	//	Get the total number of slides in this slideshow.
		var total = jQuery(this).find('p a').length;
	//	Begin on the first slide.
		var showing = 0;
		jQuery(self).find('p a').eq(showing).addClass('showing');
	
	//	This function will slide to the current "showing" slide.
		var slide = function() {
			jQuery(self).find('p a.showing').removeClass('showing');
			var xpos = 0 - (showing * 495);
			jQuery(self).find('.gallery ol').animate({
				left: xpos+'px'
			}, speed*1000);
			jQuery(self).find('p a').eq(showing).addClass('showing');
		};

	//	Automatic sliding:
		var update = function() {
		//	Increment "showing" to the next slide unless we are at the last slide.
			showing++;
			if (showing == total) {
				showing = 0;
			};
			slide();
		};
	//	Set the timer for automatic sliding.
		var timer = setInterval(update,pause*1000);

	//	User-triggered sliding:
		jQuery(self).find('p a').click(function() {
		//	Update "showing" to the slide number that the user has clicked.
			showing = jQuery(self).find('p a').index(this);
			slide();
		//	Reset the timer.
			clearInterval(timer);
			timer = setInterval(update,pause*1000);
			return false;
		});
	});
});
