// JavaScript Document

var imageList = $("#splash-images img"); // Array of images
var stopRotate = 'no'; // "no" for rotation, "yes" for rotation to stop
var flipspeed = 4; // Number of seconds between flips
var curImage = 0; // Image to start displaying - recommend to keep at 0
var numImages = imageList.size() - 1; // Gets the size of the array of images

if (imageList.length > 1) {
	$(document).ready(function() {
		rotateImages();
		

		$(imageList).each(
			function(index, domEle) {
				if(index == 0) {
					$(domEle).addClass("active");
				} else {
					$(domEle).hide();
				}
				var curIndex = index + 1;
				$(domEle).attr("id", "image" + curIndex);
			}
		);
	
	});
}

function viewSection(id) {
	$(imageList).removeClass("active");
	$(imageList[id]).addClass("active");
	$(imageList).each(function() {
		if($(this).is(":visible"))
		{
			$(this).fadeOut("slow");
		}
	});
	$(imageList[id]).fadeIn("slow");
}

function rotateImages() {
	if (stopRotate != 'yes') {
		setTimeout(function() { 
			if (curImage < numImages) {
				curImage++;
			} else {
				curImage = 0;
			}
			if (stopRotate == 'no')
			{
				viewSection(curImage);
			}
			rotateImages();
		}, flipspeed*1000);
	}
}

