var arrPic = new Array(3);
var idx1 = 0;
arrPic[0] = 'home-photos-1'; // loading set one
arrPic[1] = 'home-photos-2';
arrPic[2] = 'home-photos-3';

// preload images
if (document.images) {
	var i;
	var img;

	for( i=0; i < arrPic.length; i++){
		img = newImage( 'images/'+ arrPic[i]+ '.jpg' );			
	}
}

function rotateImages(){
	idx1 = rotatePic( '0', idx1 );
	// call it and rotate again
	setTimeout( 'rotateImages()', 5000); 
}

function rotatePic( picImage, idx ){
	var img = document.getElementById('homepic1');
	var path = 'images/';
	
	if( typeof( img ) == 'object' ){
		// change the src files
		var imageIndex = idx;
		while(imageIndex == idx ){
		   imageIndex = Math.round( Math.random() * (arrPic.length-1));
		} // end of while
		
		img.src = path + arrPic[imageIndex]+ '.jpg';
	} else {
		// do nothing
		alert('nothing going on');
	}
	
	return imageIndex;
}


function newImage( arg ) {
	if (document.images) {
	rslt = new Image();
	rslt.src = arg;
	return rslt;
	}
	}
	
	
	window.onload = function() {
		
		rotateImages();
	}