function revolve(images, i){
	var src = images[i++];
	var delay = Math.ceil(((Math.random()*4)+2)*1500);
	if(i == images.length) i=0;
	var nextSrc = images[i];
	$('img[src="' + src +'"]').removeClass('selected');
  $('img[src="' + nextSrc + '"]').css({"z-index": 50}).addClass('selected');
  $('img[src="' + src +'"]').css({"z-index": 100}).fadeOut(1500, function(){
  	$(this).css({"z-index": 0}).show();
  });	
	timer = setTimeout(function(){revolve(images, i)}, delay + 1500);
}

$(document).ready(function(){
	$('img').hide();
});

$(window).load(function(){
	$('.image, .biopic').each(function(){
		$('img:first', this).fadeIn(function(){
			$('.image img').show();
		});
	})
	$('.image').each(function(){
		delay = Math.ceil(((Math.random()*7)+2)*1000);
		var images = new Array;
		$("img", this).each(function(){
			images.push($(this).attr('src'));
		});
		$('img[src="' + images[0] + '"]', this).css({"z-index": 100}).addClass('selected');
		$('img[src="' + images[1] + '"]', this).css({"z-index": 50});
		timer = setTimeout(function(){revolve(images, 0)}, delay + 1500);
	});
});
