// CHANGE THIS TO THE AMOUNT OF SECONDS YOU WANT THE CYCLE INTERVAL TO BE
var cycleInterval = 10; // 5 seconds between slides

var isCycling = 1;
var currentSlide = 1;
var slideCount = 4;

var isAnimating = 0;

$( document ).ready(function(){	
	// Start cycling
	setTimeout( "cycle()", cycleInterval * 600 );
	
	$( '.btn' ).click(function(){
		if( isAnimating == 0 )
		{
			isCycling = 0;
			isAnimating = 1;
			
			var nextSlide = parseInt( $( this ).attr( 'rel' ) );
			$( '#hide_' + currentSlide ).fadeOut( 'slow', function(){
				$( '#step' + currentSlide + 'a' ).attr( 'id', 'step' + currentSlide );
				$( '#step' + nextSlide ).attr( 'id', 'step' + nextSlide + 'a' );
	
				$( '#hide_' + nextSlide ).fadeIn( 'slow', function(){
					currentSlide = nextSlide;
					isAnimating = 0;
					
					setTimeout( "restartCycle()", ( cycleInterval * 600 ) * 2 )
				});
			});
		}
		
		return false;
	});
});

function cycle()
{
	if( isCycling == 1 )
	{
		var nextSlide = ( currentSlide < 4 ) ? ( currentSlide + 1 ) : 1;
		//alert( nextSlide );
		
		// Switch the slides
		isAnimating = 1;
				
		$( '#hide_' + currentSlide ).fadeOut( 'slow', function(){
			$( '#step' + currentSlide + 'a' ).attr( 'id', 'step' + currentSlide );
			$( '#step' + nextSlide ).attr( 'id', 'step' + nextSlide + 'a' );

			$( '#hide_' + nextSlide ).fadeIn( 'slow', function(){
				currentSlide = nextSlide;
				isAnimating = 0;										  
			});													   
		});
	}
	
	setTimeout( "cycle()", cycleInterval * 600 );
}

function restartCycle()
{
	isCycling = 1;
}
