/***********************************************************/
// Project:		Polyurethane Slideshow
// Useage:		Include on Polyurethane Homepage
// Author:		Jonathon VanHamlin - NA31631
/***********************************************************/

//Global Vars
	var interval;
	var currentIndex = 2; //next slide change goes to slide 2
	var currentSlide;
		
	function start(){
		interval = setInterval ( "startSlideshow()", 5000 );
	}
		
	function pause(){
		clearInterval(interval);
	}
			
	function hideAll(){
		$('#slide1').fadeOut(1000);
		$('#slide2').fadeOut(1000);
		$('#slide3').fadeOut(1000);
		$('#slide4').fadeOut(1000);
		$('#thumb1 img:last').fadeIn(1000);
		$('#thumb2 img:last').fadeIn(1000);
		$('#thumb3 img:last').fadeIn(1000);
		$('#thumb4 img:last').fadeIn(1000);
	}
			
	function startSlideshow(){
		if (currentIndex==1){
			hideAll();
			$('#slide1').fadeIn(1000);
			$('#thumb1 img:last').fadeOut(1000);
			currentIndex++;
		}
		else if (currentIndex==2){
			hideAll();
			$('#slide2').fadeIn(1000);
			$('#thumb2 img:last').fadeOut(1000);
			currentIndex++;
		}
		else if (currentIndex==3){
			hideAll();
			$('#slide3').fadeIn(1000);
			$('#thumb3 img:last').fadeOut(1000);
			currentIndex++;
		}
		else if (currentIndex==4){
			hideAll();
			$('#slide4').fadeIn(1000);
			$('#thumb4 img:last').fadeOut(1000);
			currentIndex = 1;
		}
	}
		
	function slideClick(){
		pause();
		hideAll();
		$(currentSlide).fadeIn(1000);
		//start(); //Disabled rotation after a slide is clicked based on UX reccomendations
	}

//jQuery on page loaded--------------------------------		
    $(document).ready(function() {
			
		$(window).load(function() { //Preload images before starting slideshow
			start();
		});
					
		$('#thumb1').click(function () {
			if (currentIndex != 2){
				currentSlide = $('#slide1');
				currentIndex=2; //sets the slideshow loop to resume the next slide in sequence
				slideClick();
				$('#thumb1 img:last').fadeOut(1000);//Fades thumbnail back to color
			}
		});
		$('#thumb2').click(function () {
			if (currentIndex != 3){
				currentSlide = $('#slide2');
				currentIndex=3; //sets the slideshow loop to resume the next slide in sequence
				slideClick();
				$('#thumb2 img:last').fadeOut(1000);//Fades thumbnail back to color
			}
		});
		$('#thumb3').click(function () {
			if (currentIndex != 4){
				currentSlide = $('#slide3');
				currentIndex=4; //sets the slideshow loop to resume the next slide in sequence
				slideClick();
				$('#thumb3 img:last').fadeOut(1000);//Fades thumbnail back to color
			}
		});
		$('#thumb4').click(function () {
			if (currentIndex != 1){
				currentSlide = $('#slide4');
				currentIndex=1; //sets the slideshow loop to resume the next slide in sequence
				slideClick();
				$('#thumb4 img:last').fadeOut(1000);//Fades thumbnail back to color
			}
		});
			
	});
//End document.ready()-----------------------------
