// slideshow.js

$(document).ready(function() {
	$('#slideshow').ready(function() {
		var slideshow = $('#slideshow');
		var view_duration = 5;
		var effect_duration = 1000;
		
		slideshow.each(function() {
			var index = 0;
			var slideshow = $(this);
			var items = slideshow.find('.item');
			
			slide = function() {
				current = index;
				
				if(index >= items.size() - 1) {
					index = 0;
				} else {
					index = index + 1;
				}
				
				items.eq(index).fadeIn(effect_duration);
				items.eq(current).fadeOut(effect_duration);
				
			};
			
			// hide all elements except the first
			items.slice(1).hide();
			
			if(items.size() > 1) {
				setInterval(slide, view_duration * 1000);
			}
		});
	});
});
