// JavaScript Document

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

if (images.length > 1) {
	$(document).ready(function() {
		rotateImages();
		
		images.each(
			function(index, domEle) {
				var curIndex = index + 1;
			}
		);
	});
}

function viewSection(id) {
	$('#thumb-1 li').removeClass("active");
	$('#image'+id).addClass("active");
	images.each(function() {
		if($(this).is(":visible"))
		{
			$(this).fadeOut();
		}
	});
	$('#image'+id+'_holder').fadeIn();
}

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