var SlideShow = {
    img: null,
    imgActual: null,
    contenedorImgs: null,
    coleccionImgs: null,
    run: function (contenedorImgs, coleccionImgs) {
        this.img = null;
        this.imgActual = 0;
        this.contenedorImgs = contenedorImgs;
        this.coleccionImgs = coleccionImgs;

        if (this.contenedorImgs && this.coleccionImgs.length > 0 ) {
            for (var img in this.coleccionImgs) {
                this.coleccionImgs[img] = $( document.createElement('img') ).attr('src', this.coleccionImgs[img]);
            }

            this.img = $( document.createElement('img') ).attr('src', this.coleccionImgs[this.imgActual].attr('src'));
            this.contenedorImgs.empty().append( this.img );

            //this.img.hide().fadeIn("slow", function () {
                window.setTimeout(SlideShow.cambiarImagen, 3000);
            //});
        }
    },
    cambiarImagen: function ()
    {
        SlideShow.imgActual++;
        if (SlideShow.imgActual >= SlideShow.coleccionImgs.length) {
            SlideShow.imgActual = 0;
        }

        SlideShow.efectuarCambio();

        window.setTimeout(SlideShow.cambiarImagen, 3000);
    },
    efectuarCambio: function ()
    {
        this.img.fadeOut("slow", function () {
            SlideShow.img.attr('src', SlideShow.coleccionImgs[SlideShow.imgActual].attr('src'));
            return SlideShow.img.fadeIn("slow");
        });
    }
};
$(window).load(function () {
    SlideShow.run(
        $('#slideshow'),
        ['/public/imgs/fade/026.jpg',
        'public/imgs/fade/003.jpg',
        'public/imgs/fade/005.jpg',
        'public/imgs/fade/011.jpg',
        'public/imgs/fade/008.jpg',
        'public/imgs/fade/014.jpg',
        'public/imgs/fade/013.jpg',
        'public/imgs/fade/015.jpg',
        'public/imgs/fade/021.jpg',
        'public/imgs/fade/017.jpg',
        'public/imgs/fade/023.jpg',
        'public/imgs/fade/027.jpg']
    );
});
