You're probably trying to do something more like this
$(function() {
var i = 1;
(function doAnimation(){
$('.slide'+i+'-img').delay(1000).fadeOut(500, function(){
$(this).attr('class', 'slide' + (i = i==3 ? 1 : i+1) + '-img').fadeIn(500, doAnimation);
});
})();
});
just iterating the class with a variable inside a recurring function.