// JavaScript Document for Johnson-Companies

//TO ADJUST THE PHOTO ROTATION, GO TO THE END OF THE CODE AND ADJUST THE FOLLOWING LINE:
//photoRotation = setInterval("rotatePhotos()", 1000); //ADJUST ROTATION TIME: Every 1000 = 1 second.

//Start rotating Photos
var currentIndex = 0; // Determines the index of the current Photo to display
var previousIndex = 0; // Determines the index of the previous Photo to hide it
var numberPhotos = new Array(); // Array for the list of Photos
var photoRotation; // The interval of time before the next photo is displayed

// gets all the html tags based on whether the browser uses the IE DOM or the W3C DOM
// Create an array from the html tags that includes only those with the specified class attribute
function getElementsByClass(classname) {
	var counter=0; //creates an index number for the list of Photos
	var allTags = document.all? document.all : document.getElementsByTagName("*"); 
		for ( var i=0; i<allTags.length; i++) {
		if (allTags[i].className == classname)
			numberPhotos[counter++] = allTags[i];
	}
}

// rotates the display of the Photos
function rotatePhotos() {
	currentIndex=(currentIndex < numberPhotos.length-1) ? currentIndex+1 : 0;
	previousIndex=(currentIndex==0) ? numberPhotos.length-1 : currentIndex-1;
	numberPhotos[previousIndex].style.display="none";  // hides the old Photo
	numberPhotos[currentIndex].style.display="block";  // displays the new Photo
}

window.onload=function() {
	if (document.all || document.getElementById) {
		getElementsByClass("Photo");
		photoRotation = setInterval("rotatePhotos()", 3000); //ADJUST ROTATION TIME: Every 1000 = 1 second.
	}
}


