// JavaScript Document

var images = $("#rotator .adimageHolder"); // Array of images
var stopRotate = 'no'; // "no" for rotation, "yes" for rotation to stop
var flipspeed = 7; // 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() {

       $('#image'+curImage+'_holder').fadeIn();
        if(curImage < numImages) {
            curImage++;
        }

        rotateImages();

		$('#rotator a').hover(function(){
			$(this).parent().addClass("hover");
		},function(){
			$(this).parent().removeClass("hover");
		});
	});
}

function viewSection(id) {
   $('#image'+id+'_holder').addClass("active");
   $('#image'+id+'_holder').addClass("visible");
    images.each(function() {
        if($(this).is(":visible"))
		{
			$(this).fadeOut();
		}
	});
   $('#image'+id+'_holder').fadeIn();
}

function rotateImages() {
	if (stopRotate != 'yes') {
		setTimeout(function() {
			if (curImage < numImages) {
				curImage++;
			} else {
				curImage = 1;
			}
			if (stopRotate == 'no')
			{
				viewSection(curImage);
			}
			rotateImages();
		}, flipspeed*1000);
	}
}
