var ss = (function(){
	var current = false;
	var nextImg = false;
	var ssTimeout = 5000;
	var fadeTime = 500;
	var images = false;
	
	return{
		swapImages: function(){
			current = nextImg;
			nextImg = false;
		},
		
		next: function(){
			if(current){
				nextImg = $(current.next());
				if(nextImg.length < 1){
					nextImg = $(images[0]);
				}
				
				nextImg.css('zIndex',current.css('zIndex'));
				var zi = new Number(current.css('zIndex'));
				current.css('zIndex',Math.round(zi+1));
				nextImg.fadeTo(0,1);
				nextImg.show();
				current.fadeTo(fadeTime,0,function(){
					$(this).hide();
					ss.swapImages();
				});
				setTimeout("ss.next();",ssTimeout);
			}
		},
		
		init: function(){
			var slideshow = $('#slideshow-images');
			if(slideshow.length > 0){
				images = slideshow.find('img');
				current = $(images[0]);
				current.css('zIndex','100');
				setTimeout("ss.next();",ssTimeout);
			}
		}
	}
})();

$(window).load(function(){
	ss.init();
});
