﻿var delays = [300, 0, 500];
function slideSwitch() {

	$('#slideshow li.prev').removeClass('prev');

	var active = $('#slideshow li.active');
	if (active.length == 0) active = $('#slideshow li:last');
	active.addClass('prev').removeClass('active');

	var next = active.next();
	if (active.next().length == 0) {
		next = $('#slideshow li:first');
	}
	var imgs = next.find('img');
	imgs.css({ opacity: 0.0 });
	next.addClass('active');
	if (imgs.length < 2) {
		// Just animate it at once
		imgs.delay(400).animate({ opacity: 1.0 }, 670);
	} else {
		// Load delayed
		imgs.delay(600).each(function (index, elem) {
			$(this).delay(delays[index]).animate({ opacity: 1.0 }, 670);
		});
	}

	var prevImgs = active.find('img');
	prevImgs.animate({ opacity: 0.0 }, 670, function () {
		active.removeClass('prev');
	});

}

$(document).ready(function () {
	setInterval("slideSwitch()", 4000);
});