
$(function() {
			
	$("#viewer").removeClass("js-disabled");
	$("<div>").attr("id", "container").css({ position:"absolute"}).width($(".wrapper").length * 126).height(35).appendTo("div#viewer");
	$(".wrapper").each(function() {
		$(this).appendTo("div#container");
	});

	var duration = $(".wrapper").length * 2000;
	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");
	var animator = function(el, time, dir) {
 
		if(dir == "rtl") {
	  
			el.removeClass("ltr").addClass("rtl");
			el.animate({ left:"-" + el.width() + "px" }, time, "linear", function() {
			$(this).css({ left:$("div#scroller").width(), right:"" });
			animator($(this), duration, "rtl");
			($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			
		});

	} else {
	
		el.removeClass("rtl").addClass("ltr");
		el.animate({ left:$("div#viewer").width() + "px" }, time, "linear", function() {

				$(this).css({ left:0 - $("div#container").width() });
				animator($(this), duration, "ltr");
				($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			
			});
		}
	}

	animator($("div#container"), duration, direction);
});

