			$(function() 
			{
			    var number_of_elements_container_1 = Math.ceil($(".wrapper").length/2);
			    var number_of_elements_container_2 = $(".wrapper").length - number_of_elements_container_1;
			
			    //create new container for images
				$("<div>").attr("id", "container").css({ position:"absolute"}).width(number_of_elements_container_1 * 66).height(102).appendTo("div#brands");
				$("<div>").attr("id", "container_2").css({ position:"absolute"}).width(number_of_elements_container_2 * 66).height(102).appendTo("div#brands");
			  	
				//add images to container
				$(".wrapper").each(function(i) {
					if (i < number_of_elements_container_1)
						$(this).appendTo("div#container");
					else
						$(this).appendTo("div#container_2");					
				});
				
				//work out total travel distance
				var totalDistance = $(".wrapper").length * 66;
				
				//work out duration of anim based on number of images (1 second for each image)
				var duration = number_of_elements_container_1 * 2000;
				
				//work out duration of anim based on number of images (1 second for each image)
				var duration2 = (number_of_elements_container_2 + number_of_elements_container_1) * 2000;
				
				//store speed for later (distance / time)
				var default_speed = parseInt($("div#container").width()) / duration;
				
				//store speed for later (distance / time)
				var speed = parseInt($("div#container").width()) / duration;
								
				//set direction
				var direction = "rtl";
				
				//set initial position and class based on direction
				(direction == "rtl") ? $("div#container").css("left", "0px").addClass("rtl") : $("div#container").css("right", "0px").addClass("ltr") ;
				(direction == "rtl") ? $("div#container_2").css("left", $("div#container").width()+"px").addClass("rtl") : $("div#container").css("right", "0px").addClass("ltr") ;
				
				//animator function
				var animator = function(el, time, dir, other) 
				{					
					
					//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() 
						{					
							var duration_new = (el.width() + $(other).width()) / speed;	
							//reset container position
							$(this).css({ left:(parseInt($(other).css("left"))+$(other).width())+"px", right:"" });
							
							//restart animation
							animator($(this), duration_new, "rtl", other);						
						});
					} else 
					{
	  				    //add direction class
						el.removeClass("rtl").addClass("ltr");
					
						//animate the el
						el.animate({ left:$("div#brands").width()+"px" }, time, "linear", function() 
						{					
							var duration_new = (el.width() + $(other).width()) / speed;		
							//reset container position
							$(this).css({ left:(parseInt($(other).css("left"))-el.width())+"px", right:"" });
							
							//restart animation
							animator($(this), duration_new, "ltr", other);		
						});
					}
				}
				
				//start anim
				animator($("div#container"), duration, direction, "div#container_2");
				animator($("div#container_2"), duration2, direction, "div#container");
				
				//pause on mouseover
				$("a.wrapper").live("mouseover", function() 
				{
					//stop anim
					$("div#container, div#container_2").stop(true);
					
					//variable to hold trigger element
					var title = $(this).attr("title");
				});
				
				//restart on mouseout
				$("a.wrapper").live("mouseout", function(e) 
				{														
					//work out distance left to travel
					var distanceLeft; 
					var distanceLeft2; 
					
					if ($("div#container").hasClass("ltr")) 
					{
						distanceLeft = $("div#brands").width() - (parseInt($("div#container").css("left")));
						distanceLeft2 = $("div#brands").width() - (parseInt($("div#container_2").css("left")));
					}else
					{
						distanceLeft = $("div#container").width() + (parseInt($("div#container").css("left")));
						distanceLeft2 = $("div#container_2").width() + (parseInt($("div#container_2").css("left")));
					}
					
					//new duration is distance left / speed)
					var newDuration = distanceLeft / speed;
					var newDuration2 = distanceLeft2 / speed;
				
					//restart anim
					animator($("div#container"), newDuration, $("div#container").attr("class"), "div#container_2");
					animator($("div#container_2"), newDuration2, $("div#container").attr("class"), "div#container");

				});
												
				//handler for ltr button
				$("#ltor").live("click", function() 
				{
				 	if ($("div#container").hasClass("ltr") && (speed < default_speed + 0.2)) {speed += 0.05;}
					else {speed = default_speed;}

					//stop anim
					$("div#container, div#container_2").stop(true);
					
					//move to other side if container is off screen
					if (parseInt($("div#container").css("left")) > $("div#brands").width())
					{
						$("div#container").css("left", (parseInt($("div#container_2").css("left")) - $("div#container").width())+"px");
					}
					
					if (parseInt($("div#container_2").css("left")) > $("div#brands").width())
					{
						$("div#container_2").css("left", (parseInt($("div#container").css("left")) - $("div#container_2").width())+"px");
					}
				
					//swap class names
					$("div#container").removeClass("rtl").addClass("ltr");
															
					//work out remaining distance
					distanceLeft = $("div#brands").width() - (parseInt($("div#container").css("left")));
					distanceLeft2 = $("div#brands").width() - (parseInt($("div#container_2").css("left")));
					
					//new duration is distance left / speed)
					var newDuration = distanceLeft / speed;
					var newDuration2 = distanceLeft2 / speed;
					
					//restart anim
					animator($("div#container"), newDuration, "ltr", "div#container_2");
					animator($("div#container_2"), newDuration2, "ltr", "div#container");
				});
				
				//handler for rtl button
				$("#rtol").live("click", function() 
				{
				 	if ($("div#container").hasClass("rtl") && (speed < default_speed + 0.2)) {speed += 0.05;}
					else {speed = default_speed;}
					
					//stop anim
					$("div#container, div#container_2").stop(true);
					
					//move to other side if container is off screen
					if (parseInt($("div#container").css("left")) < -$("div#container").width())
					{
						$("div#container").css("left", (parseInt($("div#container_2").css("left")) + $("div#container_2").width())+"px");
					}
					
					if (parseInt($("div#container_2").css("left")) < -$("div#container_2").width())
					{
						$("div#container_2").css("left", (parseInt($("div#container").css("left")) + $("div#container").width())+"px");
					}
					
					//swap class names
					$("div#container").removeClass("ltr").addClass("rtl");
															
					//work out remaining distance
					distanceLeft = $("div#container").width() + (parseInt($("div#container").css("left")));
					distanceLeft2 = $("div#container_2").width() + (parseInt($("div#container_2").css("left")));
					
					//new duration is distance left / speed)
					var newDuration = distanceLeft / speed;
					var newDuration2 = distanceLeft2 / speed;
				
					//restart anim
					animator($("div#container"), newDuration, "rtl", "div#container_2");
					animator($("div#container_2"), newDuration2, "rtl", "div#container");
				});
			});
