 
(function($) {
    /*
    * A basic imageScroller Image Carousel.
    * http://net.tutsplus.com/tutorials/javascript-ajax/building-a-jquery-image-scroller/
    *
    */
    $.fn.imageScroller = $.fn.imagescroller = function() {
        $("#divLogos").removeClass("js-disabled");

        //create new container for images
        $("<div>").attr("id", "container")
            .css({ position: "absolute" })
            .width($("div#divLogos img").length * 210)
            .height(60)
            .appendTo("div#divLogos");

        //add images to container
        $("div#divLogos img").each(function() {
            $(this).css("opacity", "0.5").appendTo("div#container");
        });

        //work out duration of anim based on number of images (2 seconds for each image)
        var duration = $("div#divLogos img").length * 1000;

        //store speed for later (distance/time)
        var speed = (parseInt($("div#container").width()) + parseInt($("div#divLogos").width())) / duration;

        //set initial position of container
        $("div#container").css("left", $("div#divLogos").width());

        //animator function
        var animator = function(el, time) {
            //right to left

            var i = 0;
            var position = $("div#divLogos").width();
            var imgslength = el.find('img').length;

            for (j = 0; j <= imgslength; j = j + 1) {
                position = position - 210;

                el.animate({ left: position + "px" }, time / imgslength + 1, "linear", function() {
                    if (i == imgslength) {
                        el.css({ left: $("div#divLogos").width(), right: "" })
                        animator(el, time);
                    }
                    i++;
                });
                if (j != imgslength) {
                    el.delay(3000);
                }
            }

            //animate the el
            /*el.animate({ left: "-" + el.width() + "px" }, time, "linear", function() {
            //reset container position
            $(this).css({ left: $("div#divClients").width(), right: "" })

                //restart animation
            animator($(this), duration);
            });*/
        }

        //start anim
        animator($("div#container"), duration);
    };
})(jQuery);
