Jquery making image scroller alternate

I have following code which scroll images from left to right.
Can I modify the code so that the images moves alternate.(i.e. left to right and again right to left)

			var duration = 10000;
			var speed = (parseInt($("div#container").width()) + parseInt($("div#viewer").width())) / duration;
			var direction = "rtl";
			(direction == "rtl") ? $("div#container").css("left", $("div#viewer").width()).addClass("rtl") : $("div#container").css("left", 0 - $("div#container").width()).addClass("ltr") ;
			//animator function
			var animator = function(el, time, dir) {
				//which direction to scroll
				if(dir == "rtl") {
				  //add direction class
					el.removeClass("ltr").addClass("rtl");
					//animate the el
					el.animate({ left:"-" + el.width() + "px" }, time, "linear", function() {
						//reset container position
						$(this).css({ left:$("div#imageScroller").width(), right:"" });
						//restart animation
						animator($(this), duration, "rtl");
						//hide controls if visible
						($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			
					});
				}

}

If you only have 2 images, you can do it like so

var duration = 10000;
var speed = (parseInt($(“div#container”).width()) + parseInt($(“div#viewer”).width())) / duration;
var direction = “rtl”;
(direction == “rtl”) ? $(“div#container”).css(“left”, $(“div#viewer”).width()).addClass(“rtl”) : $(“div#container”).css(“left”, 0 - $(“div#container”).width()).addClass(“ltr”) ;
//animator function
var animator = function(el, time, dir) {
//which direction to scroll
if(dir == “rtl”) {
//add direction class
el.removeClass(“ltr”).addClass(“rtl”);
//animate the el
el.animate({ left:“-” + el.width() + “px” }, time, “linear”, function() {
//reset container position
$(this).css({ left:$(“div#imageScroller”).width(), right:“” });
//restart animation
animator($(this), duration, dir == “rtl” ? “ltr” : “rtl”);
//hide controls if visible
($(“div#controls”).length > 0) ? $(“div#controls”).slideUp(“slow”).remove() : null ;
});
}
}

If you have more than 2 images however the code gets WAY more involved (would take about an hour or so to write, so I won’t write it for you, sorry)