var current = 1;
var total;
var timeout;

window.addEvent('domready', function(e){
	var slides = $$('.homeSlideshow');
	total = slides.length;
	
	if(total > 1) {
		$$('.homeSlideshow').each(function(e) {
			if(e.id != 'slideImg'+current)
				$(e.id).setStyle('opacity', 0);
		});
		
		$$('.homeSlideshow').addEvent('mouseenter', function(e) {
			clearTimeout(timeout);
		});
		$$('.homeSlideshow').addEvent('mouseleave', function(e) {
			timeout = setTimeout("slideImg()", 4000);
		});
		
		timeout = setTimeout("slideImg()", 4000);
	}
});

function slideImg() {
	$('slideImg'+current).tween('opacity',0);
	
	current++;
	if(current > total)
		current = 1;
		
	$('slideImg'+current).tween('opacity',1);
	
	timeout = setTimeout("slideImg()", 4000);
}
