var nc_anim_images =
{
    num_images: 0,
    div_id: [],
    container_id: "slide",
    container: null,
    images_obj: [],
    image_width: 160,
    image_h_border: 10,
    h_max: 850,
    interval_id: 0,
    loop_count: 0,
    frame_interval: 40,
    default_frame_interval: 40,
    pause_length: 25,
    mouseover: 0,
    mouseover_class: "mouseover",
    mouseout_class: "",

    init: function ()
    {
        for (i = 0, h_pos = -this.image_width - this.image_h_border; i < slides_id.length; i++, h_pos += this.image_width + this.image_h_border) {
            this.div_id[i] = slides_id[i];
            this.images_obj[i] = {
                ref: document.getElementById(this.div_id[i]),
                start_pos: h_pos
            };
            this.images_obj[i].ref.style.left = h_pos+"px";
        }
        this.num_images = i;

        this.container = document.getElementById(this.container_id);
        if (this.container.addEventListener) {
            this.container.addEventListener("mouseover", nc_anim_images.mousestop, false);
            this.container.addEventListener("mouseout", nc_anim_images.mousestop, false);
        } else if (this.container.attachEvent) {
            this.container.attachEvent("onmouseover", nc_anim_images.mousestop);
            this.container.attachEvent("onmouseout", nc_anim_images.mousestop);
        }
    },

    move: function ()
    {
        var img = null;
        var pos_increment = this.calc_slide_mode_1();
        var new_pos = 0;
        var loop_end = 0;

        if (this.frame_interval == this.pause_length) {
            this.stop();
            this.frame_interval = this.default_frame_interval;
            this.start();
        }

        for (i = 0; i < this.div_id.length; i++) {
            img = this.images_obj[i];
            new_pos = img.start_pos + pos_increment;

            if (new_pos == this.h_max) {
                //On a fini de glisser
                loop_end = 1;
            }
            img.ref.style.left = new_pos+"px";
        }

        if (loop_end == 1) {
            //On a fini de glisser.
            //Calcul des nouvelles positions des images
            for (i = 0; i < this.div_id.length; i++) {
                img = this.images_obj[i];
                img.start_pos += pos_increment;
                if (img.start_pos == this.h_max) {
                    img.start_pos = 0 - this.image_width - this.image_h_border;
                }
            }
            this.stop();
            this.frame_interval = this.pause_length;
            this.loop_count = 0;
            this.start();
        } else {
            ++this.loop_count;
        }
    },

    start: function ()
    {
        nc_anim_images.interval_id = setInterval("nc_anim_images.move()", nc_anim_images.frame_interval);
    },

    stop: function ()
    {
        clearInterval(nc_anim_images.interval_id);
    },

    calc_slide_mode_1: function ()
    {
        //~ var positions = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 91,
            //~ 103, 115, 127, 139, 149, 157, 163, 167, 169, 170];
        var positions = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28,
            30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
            64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96,
            98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124,
            126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150,
            152, 154, 156, 158, 160, 162, 164, 166, 168, 170];

        return positions[this.loop_count < positions.length ? this.loop_count : positions.length - 1];
    },

    mousestop: function(e)
    {
        var thiz = nc_anim_images;
        var css_class = "";

        if (thiz.mouseover == 0) {
            thiz.mouseover = 1;
            css_class = thiz.mouseover_class;
            thiz.stop();
        } else {
            thiz.mouseover = 0;
            thiz.frame_interval = thiz.default_frame_interval;
            css_class = thiz.mouseout_class;
            thiz.start();
        }

        thiz.container.setAttribute("class", css_class);
    }
};


function start_animation () {
    nc_anim_images.init();
    nc_anim_images.start();
}
