
var intervalID = 0;

$(document).ready(function() {
  
	//Load the slideshow
	theRotator();
	

 });


function theRotator() {

	//Set the opacity of all images to 0
	$('#imgNext1').hide();
	$('#imgNext2').hide();
	
	//Get the first image and display it (gets set to full opacity)
	//$('#slide-wrapper img:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow
	intervalID = setInterval('rotate()', 3500);
	
}

function rotate() {	

	//Get the first image
	var current = ($('#slide-wrapper img.show')  ?  $('#slide-wrapper img.show') : $('#slide-wrapper img:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#slide-wrapper img:first') : current.next()) : showCarrie());	
	

	//Set the fade in effect for the next image
	if(next) next.fadeIn(1000).addClass('show');

	//Hide the current image
	current.hide().removeClass('show');
	
}

function showCarrie()
{
	
	$('#slide-wrapper').remove();
	$('#carrie-wrapper').fadeIn(1400);
	clearInterval(intervalID);

	$("#carrie-thumb").hover(
  
		function () {

			$('#gideon-wrapper, #dr-rubin-wrapper, #barbara-and-luis-wrapper, #ben-wrapper').hide();
			$('#carrie-wrapper').fadeIn();
			
			
			
		}, function () {
			
			$('#carrie-wrapper').show();
			
			
		   }

  
	);

	$("#gideon-thumb").hover(
  
		function () {

			$('#carrie-wrapper, #dr-rubin-wrapper, #barbara-and-luis-wrapper, #ben-wrapper').hide();
			$('#gideon-wrapper').fadeIn();
			
		}, function(){
			
			$('#gideon-wrapper').show();
			
		}
	

  
	);

	$("#dr-rubin-thumb").hover(
  
		function () {

			$('#gideon-wrapper, #carrie-wrapper, #barbara-and-luis-wrapper, #ben-wrapper').hide();
			$('#dr-rubin-wrapper').fadeIn();
			
		}, function(){
				
			$('#dr-rubin-wrapper').show();
		}
	

  
	);

	$("#ben-thumb").hover(
  
		function () {

			$('#gideon-wrapper, #dr-rubin-wrapper, #barbara-and-luis-wrapper, #carrie-wrapper').hide();
			$('#ben-wrapper').fadeIn();
			
		}, function(){
				
			$('#ben-wrapper').show();
		}
	

  
	);


	$("#barbara-and-luis-thumb").hover(
  
		function () {

			$('#gideon-wrapper, #dr-rubin-wrapper, #carrie-wrapper, #ben-wrapper').hide();
			$('#barbara-and-luis-wrapper').fadeIn();
			
		}, function(){
				
			$('#barbara-and-luis-wrapper').show();
		}
	

  
	);


}

