// JavaScript Document
var imageListItems = $("#splash-links li"); // Array of images
var imageHolders = $("#splash-slides li"); // Array of images
var stopRotate = 'no'; // "no" for rotation, "yes" for rotation to stop
var flipspeed = 5; // Number of seconds between flips
var curImage = 0; // Image to start displaying - recommend to keep at 0
var numImages = imageHolders.size() -1; // Gets the size of the array of images
var tempID = "";

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

		$(imageListItems).each(
			function(index, domEle) {
				var tempSlide = "";
				if(index == 0) {
					$(domEle).addClass("active");
				} 
				$(domEle).attr("id", "image" + index);
			}
		);
	
		$('#splash-links a').click(function(){
			tempID = $(this).parent().attr("id");
			stopRotate = 'yes';
			viewSection(tempID);
			return false;
		});
	});
}

function viewSection(id) {
	$(imageListItems).removeClass("active");
	$("#"+id).addClass("active");
	$(imageHolders).each(function() {
		if($(this).is(":visible"))
		{
			$(this).children(".splash-text").fadeOut(300, function () {
				$(this).parent().fadeOut('slow');
			});
		}
	});
	var slideID = id+"-slide";
	$("#"+slideID).fadeIn('slow', function () {
		$("#"+slideID+" .splash-text").fadeIn(300);
	});
}

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

