Use a global variable that will hold currently displayed image. Something like this:
var shownImg;
function anim(selector) {
$(".images img", selector).first().appendTo($('.images', selector)).fadeOut(2000);
shownImg = $(".images img", selector).first().fadeIn(2000);
}
This way you will always know which image is currently displayed.. Here is your code updated to work like that : http://jsfiddle.net/X9n6u/