function UpdateTime() {
    ss -= 1;
    if (ss < 0) { ss = 59; mm -= 1; }
    if (mm < 0) { mm = 59; hh -= 1; }
    if (hh < 0) { hh = 23; }

    document.getElementById("hours").innerHTML = hh + "h"; +mm + "m : " + ss + "s";
    document.getElementById("minutes").innerHTML = mm + "m";
    document.getElementById("seconds").innerHTML = ss + "s";
}

$(document).ready(function() {
    var pageUrl = location.href;

    //if we are on root of folder don't update - causes exception
    if (pageUrl.substr(pageUrl.length - 1, 1) != "/") {
        $("#aspnetForm").attr("action", pageUrl.substr(pageUrl.lastIndexOf("/") + 1, pageUrl.length - pageUrl.lastIndexOf("/")));
    }
    var tabs = $(".tab");
    if (tabs.length > 0) {
        hideAllTabbedContent();
        //show first tabs content
        $(tabs.first().attr("href")).show();
        selectTab(tabs.first());
    }

    $(".tab").click(function(e) {
        //prevent default movement to hash
        e.preventDefault();
        //first hide all tabbed content on page
        hideAllTabbedContent();

        //show clicked tabs content
        $($(this).attr("href")).show();
        selectTab($(this));
    });

});

function hideAllTabbedContent() {
    $(".tab").each(function(i, item) {
        var elementID = $(item).attr("href");
        $(elementID).hide();
    });
}

function selectTab(a) {
    $(".tab").parent().css("z-index", "1");

    var parentLi = a.parent();
    parentLi.css("z-index", "5");
    var color = parentLi.css("color");
    a.parents("ul").css("border-bottom", "solid 15px " + color);
}

//------------- progress bar code. -------
var progressEnd = 0; 	// set to number of progress <span>'s.
var progressInterval = 1000; // set to time between updates (milli-seconds)
var progressAt = 10;
var progressTimer;

function progress_update() {
    if (progressAt >= progressEnd) {
        $('#timer').text(progressAt--);
    } else {
        clearInterval(progressTimer);
    }
}
function progress_stop() {
    clearInterval(progressTimer);
}
function progress_start() {
    progressAt = 10;
    progress_update();
    progressTimer = setInterval('progress_update()', progressInterval);
}

function CreateCollection(ClassName) {
    var obj = new Array();
    eval("var t=new " + ClassName + "()");
    for (_item in t) {
        eval("obj." + _item + "=t." + _item);
    }
    return obj;
}


function QuizCollection() {
    this.Add = function(obj) {
        this.push(obj);
    }
}

function Quiz(categoryName, html) {
    this.CategoryName = categoryName;
    this.Html = html;
}

$(document).ready(function() {
    loadQuizLists();
});
        
function loadQuizLists() {
    var topHtml = "";
    var categories = new Array();
    var quizCol = CreateCollection("QuizCollection");

    //group quizzes in their categories
    $("#divQuizList").find("h2").each(function() {
        var catName = $(this).text();
        categories[categories.length] = catName;

        $(this).next("ul").find("li").each(function(i, item) {
            quizCol.Add(new Quiz(catName, $(item).html()));
        });
    });

    for (var i = 0; i < categories.length; i++) {
        var categoryHtml = "<div class=\"quiz-group\"><h2>{0}</h2><ul>".replace("{0}", categories[i]);

        for (var ii = 0; ii < quizCol.length; ii++) {
            if (quizCol[ii].CategoryName == categories[i]) {
                categoryHtml += "<li>{0}</li>".replace("{0}", quizCol[ii].Html);
            }
        }
        categoryHtml += "</ul></div>";
        $("#topQuizzes").append(categoryHtml);
    }

    if ($("#ulQuizList").length > 0) {
        //load quizzes for left menu
        for (var i = 0; i < quizCol.length; i++) {
            $("#ulQuizList").append("<li>{0}</li>".replace("{0}", quizCol[i].Html));
        }
        $("#pLoader").remove();
    }
}