var count, zIndex = 1, imagesLoadedCount = 0, delay = 500;
$(initCarousel);

function initCarousel() {
	count = $('#rotator li').length;
	$('#rotator li:first').css("opacity", "1");
	$('#rotator li img').each(function() {
		if (this.complete) imagesLoadedCount++;
		else {
			$(this).bind('load', function(){imagesLoadedCount++});
		}
	});
	initRotation();
}
function initRotation() {
	if (imagesLoadedCount != count) setTimeout("initRotation()", 800);
	else {
		$('#rotator li:not(li:first)').css("display", "none").css("opacity", "1");
		setTimeout("rotate(1)", delay);
	}
}
function rotate(i) {
	if (i == count) i = 0;
	$($('#rotator li')[i]).css("display", "none").css("z-index", zIndex).fadeIn(50);
	zIndex++;
	setTimeout("rotate(" + (i+1) + ")", delay);
}
