﻿
var quizScript = function() {
    var startIndex;
    var endIndex;
    var numberOfSlidesPerScreen;

    numberOfSlidesPerScreen = 2;
    startIndex = 0;
    endIndex = numberOfSlidesPerScreen;

    this.startQuiz = function() {
        showQuizQuestions(0, 2);
    }

    function showQuizQuestions(start, end) {
        if (start <= 0) {
            $(".quiz-controls-prev").hide();
        } else {
            $(".quiz-controls-prev").show();
        }
        if (end >= $(".quiz-container div").length) {
            $(".quiz-controls-next").hide();
            $(".quiz-controls-submit").show();
        } else {
            $(".quiz-controls-next").show();
            $(".quiz-controls-submit").hide();
        }
        // Find all the content, move to the starting position and move upwards through the tree until we reach the end position
        // Then show that content - including the start position      
        $(".quiz-container div").hide().eq(start).nextUntil($(".quiz-container div").eq(end)).andSelf().show();
    }

    // Assign the behaviour for the next click event
    $(".quiz-controls-next").click(function() {
        startIndex = endIndex;
        endIndex = endIndex + numberOfSlidesPerScreen;
        showQuizQuestions(startIndex, endIndex);
    });
    // Assign the behaviour for the previous click event
    $(".quiz-controls-prev").click(function() {
        endIndex = endIndex - numberOfSlidesPerScreen;
        startIndex = startIndex - numberOfSlidesPerScreen;
        showQuizQuestions(startIndex, endIndex);
    });
    // Assign the behaviour for the try again
    $(".quiz-try-again").click(function() {
        showQuizQuestions(0, 2);
    });
};
