$(function(){
	if($("#photoPreview").length > 0 && imagesPreload()){
		var carousel = setInterval('changePic()', 5000);
	}
});

function changePic(){
	var img = $("#photoPreview > img");
	$(img).fadeTo(300, 0.1, function(){
		$(img).attr('src', '/images/carousel/'+imagesList[Math.floor(Math.random()*imagesList.length)]);
		$(img).fadeTo(300, 1);
	});
}

function imagesPreload(){
	if(imagesList != null){
		var aImages = [];
		for (var i = 0, len = imagesList.length; i < len; i++) {
			   aImages[i] = new Image();
			   aImages[i].src = imagesList[i];
		}
	}
	return true;
}


