var elementCount = 0;
var contentIndex = 0;
var rotateTimeout;
var waitTime = 5000;
var animationTime = 500;

$(document).ready(function() {
	
	$('.decisionInner').eq(0).css({opacity:1});
	
	elementCount = $('.ballOne').children('.decision').children('.decisionInner').length;
	//console.log(elementCount);
	
	if(elementCount > 1) {
		$('.intro').animate({opacity: 1}, 5000, "swing", function() {
	       	initGallery();
	   	});
	}
	
});

function initGallery() {
   	rotateTimeout = setTimeout(function() {
       	rotateImage();
   	}, waitTime);
};

function rotateImage() {
   	$('.decisionInner').eq(contentIndex).animate({opacity: 0}, 500);
   	
   	contentIndex++;

   	if(contentIndex == elementCount){
       	contentIndex = 0;
   	}   
   	
   	$('.decisionInner').eq(contentIndex).animate({opacity: 1}, 500);	
	
    rotateTimeout = setTimeout(function() {
   		rotateImage();
   	}, waitTime);
};

$(window).load(
   function() {
		
  		$('.shadowLeft').animate({
    		opacity: 1
  		}, 1000);
  		$('.ballOne').animate({
    		top: "110px"
  		}, 600, "easeInOutQuart",  function() {
    		
    		// Animation complete.
  			$('.shadowMiddle').animate({
	    		opacity: 1
	  		}, 200);
  			$('.imageOne').animate({
	    		top: "264px"
	  		}, 200, "easeInQuint",  function() {
	    		
	    		// Animation complete.
	  			$('.shadowRight').animate({
		    		opacity: 1
		  		}, 200);
	  			$('.imageTwo').animate({
		    		top: "150px"
		  		}, 200, "easeInQuint",  function() {
		    		
		    		// Animation complete.
		  			$('.imageThree').animate({
			    		top: "173px"
			  		}, 200, "easeInQuint",  function() {
			    		
			    		// Animation complete.
			  			$('.intro .box blockquote').animate({
				    		opacity: 1
				  		}, 600, function() {
				    		// Animation complete.
				    		$('.intro').css("z-index","1");
				  		});
			  		});
		  		});
	  		});
  		});
		
   }
);
