var i, factor, duration = 250, delayTime = 500; for (i = 2, factor = 0; i <= 4; i++, factor++) { galleryAnimation(i, factor); } function galleryAnimation(i, factor) { $("#pic" + i).delay(factor * delayTime).fadeIn(duration); }