$(document).ready(function() {
    if (!isPreview) {
    var currentTime = (new Date()).getTime()
    $("#id_start_time").val(currentTime)
    $("#id_end_time").val(currentTime)
    $(document).everyTime(1000, "answer_time", function(i) {
        var secondsElapsed = Math.round(timeElapsed()/1000)
        if (maxTime - secondsElapsed <= 0) {
            adjustClock(maxTime, maxTime)
            $(document).stopTime("answer_time")
            answer("")
        } else {
            adjustClock(secondsElapsed, maxTime)
        }
    })
    $('#quiztip a').lightBox() 
}
})

function adjustClock(time, maxTime) {
    var offset = 139 - time/maxTime * 135
    $("#answerclock #timbar em").css("left", String(offset) + "px")
}

function answer(answerId) {
    $("#id_total_time").val(timeElapsed())
    $("#id_answer_id").val(answerId)
    $("#question_execute_form").submit()
    return false;
}

function timeElapsed() {
    return (new Date()).getTime() - $("#id_start_time").val()
}
