var t;
var currentStep = 1;

$(document).ready(function(){
	step1Show();
});

function step1Show() {
	currentStep = 1;
	clearTimeout(t);

	$(".step1").fadeIn(1000);
	t = setTimeout(step1Hide, 5000);
}
function step1Hide() {
	clearTimeout(t);
	$(".step1").fadeOut(500);
	t = setTimeout(step2Show, 500);
}
function step2Show() {
	currentStep = 2;
	clearTimeout(t);
	
	$(".step2").fadeIn(1000);
	t = setTimeout(step2Hide, 5000);
}
function step2Hide() {
	clearTimeout(t);
    $(".step2").fadeOut(500);
    
    if (numDivs > 2) {
       t = setTimeout(step3Show, 500);
    } else {
       t = setTimeout(step1Show, 500);
    }
}
function step3Show() {
	currentStep = 3;
	clearTimeout(t);
	
	$(".step3").fadeIn(1000);
	t = setTimeout(step3Hide, 5000);
}
function step3Hide() {
	clearTimeout(t);
    $(".step3").fadeOut(500);
    if (numDivs > 3) {
       t = setTimeout(step4Show, 500);
    } else {
       t = setTimeout(step1Show, 500);
    }
}
function step4Show() {
	currentStep = 4;
	clearTimeout(t);
	
	$(".step4").fadeIn(1000);
	t = setTimeout(step4Hide, 5000);
}
function step4Hide() {
	clearTimeout(t);
    $(".step4").fadeOut(500);
    if (numDivs > 4) {
       t = setTimeout(step5Show, 500);
    } else {
       t = setTimeout(step1Show, 500);
    }
}
function step5Show() {
	currentStep = 5;
	clearTimeout(t);

	$(".step5").fadeIn(1000);
	t = setTimeout(step5Hide, 5000);
}
function step5Hide() {
	clearTimeout(t);
    $(".step5").fadeOut(500);
    if (numDivs > 5) {
       t = setTimeout(step6Show, 500);
    } else {
       t = setTimeout(step1Show, 500);
    }
}
function step6Show() {
	currentStep = 6;
	clearTimeout(t);

	$(".step6").fadeIn(1000);
	t = setTimeout(step6Hide, 5000);
}
function step6Hide() {
	clearTimeout(t);
    $(".step6").fadeOut(500);
    t = setTimeout(step1Show, 500);
}

function moveBack() {
    var switchStep = currentStep - 1;
    if (switchStep < 1) { switchStep = numDivs; }
    moveStep(switchStep);
}
function moveForward() {
    var switchStep = currentStep + 1;
    if (switchStep > numDivs) { switchStep = 1; }
    moveStep(switchStep);
}
function moveStep(switchStep) {
    $(".step1").css("display", "none");
    $(".step2").css("display", "none");
    $(".step3").css("display", "none");
    $(".step4").css("display", "none");
    $(".step5").css("display", "none");
    $(".step6").css("display", "none");
	switch(switchStep) {
		case 1:
			step1Show();
			break;
		case 2:
			step2Show();
			break;
		case 3:
			step3Show();
			break;
   		case 4:
			step4Show();
			break;
   		case 5:
			step5Show();
			break;
   		case 6:
            step6Show();
			break;
	}    
}
function pause () {
  clearTimeout(t);
}

