/* using literal array */
var theImages   =   [
                        'img/rotate/01.jpg',
                        'img/rotate/02.jpg',
                        'img/rotate/03.jpg',
                        'img/rotate/04.jpg',
                        'img/rotate/05.jpg'
                    ],
    j           =   0,
    p           =   theImages.length,
    preBuffer   =   [],
    timeoutid   =   0;

for (i = 0; i < p; i++) {	/* preload the images */
    preBuffer[ i ] = new Image();
    preBuffer[ i ].src = theImages[ i ];
}

function getRndm() {	/* get random number */
    return Math.round( Math.random() * ( p - 1 ) );
}

function showImage() {	/* set the image source, timeout for 5 seconds, & call itself */
	var img = document.getElementById( 'imgrotate' );
    clearTimeout( timeoutid );
    img.src = theImages[ getRndm() ];
    timeoutid = setTimeout(function() { showImage(); }, 5000);
}
