var count, zIndex = 1, imagesLoadedCount = 0, delay = 7500;
// $(initCarousel); // jb added this call into window load in Site.Master

function initCarousel() {
	count = $('#carousel li').length;
	$('#carousel li:first').css("opacity", "1");
	$('#carousel li img').each(function() {
	    // 08-Apr-2010 - JB - added the following to load carousel images following page load as otherwise takes forever
	    var id = this.id.toLowerCase();
        var src = '/images/hero/' + id + '.jpg';
        // if the src property doesn't contain the id then we need to change the src
        if(this.src.toLowerCase().indexOf(id) == -1)
            this.src = src;
        // 08-Apr-2010 - JB - end of addition
		if (this.complete) imagesLoadedCount++;
		else {
			$(this).bind('load', function(){imagesLoadedCount++});
		}
	});
	initRotation();
}
function initRotation() {
	if (imagesLoadedCount != count) setTimeout("initRotation()", 500);
	else {
		$('#carousel li:not(li:first)').css("display", "none").css("opacity", "1");
		setTimeout("rotate(1)", delay);
	}
}
function rotate(i) {
	if (i == count) i = 0;
	$($('#carousel li')[i]).css("display", "none").css("z-index", zIndex).fadeIn(1200);
	zIndex++;
	setTimeout("rotate(" + (i+1) + ")", delay);
}
