//adapted from previous adaptation of Tutsvalley tutorial by Doug G., 10-11
//http://tutsvalley.com/tutorials/making-a-jquery-infinite-carousel-with-nice-features/

	// var display_interval = 3000;	Length of pause before initiation of next cross-fade (in millseconds)
	var transition_speed = 2000;	// Duration of cross-fade (in millseconds)
	var pause_display = 'inline'	// Display property to apply to 'Pause' indicator when it's visible
									// ('block', 'inline', etc.)
	var loop_delay = transition_speed + display_interval;

	$(document).ready(function() {
		// Reveals feature and hides failover image if javascript
		// is running, otherwise CSS keeps feature hidden
		$('.carouselMarquee').css('display','block');
		$('.carouselFailover').css('display','none');

		// INITIALIZE THE LOOP TIMER
		var timer = setInterval(xFade,loop_delay);

		// PAUSE
		// stop the timer when user hovers over the feature
		// and display the 'Pause' indicator
		$('.carouselMarquee').hover(function(){
			clearInterval(timer)
			$('.pauseIndicator').css('display',pause_display);
			},function(){
				// hide 'pause', reset timer, and execute 
				// immediate transition when user mouses out
				timer = setInterval(xFade,loop_delay);
				$('.pauseIndicator').css('display','none');
				xFade();
			});
	
	});

	// CROSS-FADE TO NEXT IMAGE
	function xFade() {
		// Reset display property of bottom list item, 
		// then fade out the top list item, and 
		// shuffle top item to the bottom of the stack.
		$('.carouselContent li:first').css('display','list-item');
		$('.carouselContent li:last').fadeOut(transition_speed,'swing',function() {
			$('.carouselContent li:first').before($('.carouselContent li:last'));
		});
	}

	// PREVIOUS/NEXT
	// re-stack images based on user action:
	// if dir = 1, previous button was selected;
	// if dir = 0, next button was selected
	function setDir(dir) {
		if(dir == 1){
			$('.carouselContent li:last').after($('.carouselContent li:first'));
			$('.carouselContent li:last').css('display','list-item');
		}else{
			$('.carouselContent li:first').css('display','list-item');
			$('.carouselContent li:first').before($('.carouselContent li:last'));
		}
	}
