var i = 0; //initialize the counter
var nph_slide_vector; //setup the image array variable

function nph_slide_vectorshow() {
    //fade out the current slide
    fade(nph_slide_vector[i],{ duration:8 });

    //add 1 to i 
    i++;
    //check if we've reached the end of our slides, if so, rewind i to 0        
    if (i == nph_slide_vector.length) i = 0; 

    //fade in the next slide and after it's finished, loop this function
    appear(nph_slide_vector[i],{ duration:8, afterFinish: function () { nph_slide_vectorshow(); } });
}

function avvia_slideshow() {
    //hide all of the slideshow images  
    if ($('nph_slide')) {
        a = $$('#nph_slide img')
        for (var elem in a) {
            hideElement(a[elem]);
        }

        //dump the images into an array
        nph_slide_vector =  a;

        //fade in the first slide and after it's finished, start the slideshow
        appear(nph_slide_vector[0],{ duration:1, afterFinish: function () { nph_slide_vectorshow(); } });
    }
}

addLoadEvent(avvia_slideshow);