$(document).ready(function() {
	$('.slideshow').slideshow({wait: 3000, fade: 'slow'});
	
});

jQuery.fn.slideshow = function(settings) {
	return this.each(function() {
		var options = jQuery.extend({
			wait: 5000,
			fade: 'slow'
		}, settings || {});

		$this = $(this).css({position: 'relative'});
		$imgs = $('img', this);
		$imgs.hide();
		$($imgs[0]).show();

		$('.slideshow').css({display: 'block'})
		$('.no_slideshow').css({display: 'none'})

		var index = jQuery.slideshow.slideshows.length;

		jQuery.slideshow.slideshows[index] = {
			object: $this,
			imgs: $imgs,
			wait: options.wait,
			fade: options.fade,
			current: null
		}

		setTimeout('jQuery.slideshow.run(' + index + ')', 0);
	});
}

jQuery.slideshow = {
	slideshows: [],
	run: function(index) {
		var slideshow = jQuery.slideshow.slideshows[index];
		var prev = null;
		if ( slideshow.current === null ) {
			slideshow.current = 0;
		} else if ( slideshow.current == slideshow.imgs.length-1 ) {
			slideshow.current = 0;
			prev = slideshow.imgs.length-1;
		} else {
			prev = slideshow.current;
			slideshow.current++;
		}

		if ( prev !== null ) {
			$img = $(slideshow.imgs[slideshow.current]).css({zIndex: 100});
			if ( !$img[0].complete ) {
				slideshow.current--;
			} else {
				$(slideshow.imgs[prev]).css({zIndex: 0});
				$img.fadeIn('slow', function() {
					$(slideshow.imgs[prev]).hide();
				});
			}
		}
		setTimeout('jQuery.slideshow.run(' + index + ')', slideshow.wait);
	}
}