$(document).ready(function(){
    var mainCount=0;
	var thumb1Count = 1;
	var thumb2Count = 2;
    var imageCount = $('#image img').size();
	$('#main-image img').clone().appendTo('.thumb');			
	
	$('#main-image img').hide();
	$('#main-image img:nth-child(1)').show();
	$('.thumb1 img').hide();
	$('.thumb1 img:nth-child(2)').show();
	$('.thumb2 img').hide();
	$('.thumb2 img:nth-child(3)').show();

	
	
	if(imageCount>2){
        setInterval(imageTransition,5000); //number of seconds between each transition
    }

    function imageTransition() {
			
			
			//rotate main image
			$('#main-image img:eq('+mainCount+')').fadeOut(2000);
			if(mainCount<imageCount-1){
				mainCount++;
			} else {
				mainCount=0;
			}
			$('#main-image img:eq('+mainCount+')').fadeIn(2000); 
			
			//rotate thumb1
			$('.thumb1 img:eq('+thumb1Count+')').fadeOut(1600);
			if(thumb1Count<imageCount-1){
				thumb1Count++;
			} else {
				thumb1Count=0;
			}
			$('.thumb1 img:eq('+thumb1Count+')').fadeIn(1600); 
			
			//rotate thumb2
			$('.thumb2 img:eq('+thumb2Count+')').fadeOut(1200);
			if(thumb2Count<imageCount-1){
				thumb2Count++;
			} else {
				thumb2Count=0;
			}
			$('.thumb2 img:eq('+thumb2Count+')').fadeIn(1200); 			
    }	
});
