﻿

handleDrag = function(e, i) {
    vChange((i.position.left/2.5), i.helper.attr('id'));
    $('.tracksHowto').customFadeOut('slow');
}



handleStop = function(e, i) {
    var reviewer = i.helper.attr('reviewer');
    var reviewed = i.helper.attr('reviewed');
    var question = i.helper.attr('question');
    var level = (i.position.left / 2.5);


    $.get('genericAuth.asmx?T=REVIEW&REVIEWER=' + reviewer + '&REVIEWED=' + reviewed + '&LEVEL=' + level + '&QUESTION=' + question);

}





vChange = function(v, id) {

    

    if (v >= 0 && v <= 100) {
        $('#' + id + '_q3').css('color', otoh(0));
        if (v <= 50) $('#' + id + '_q2').css('color', otoh(0));
        $('#' + id + '_q1').css('color', otoh(Math.abs(((v - 100) / 100.0))));
    }


    if (v >= 50 && v <= 100) {
        l = v - 50;
        $('#' + id + '_q2').css('color', otoh(Math.abs(((l) / 100.0)) * 2));
    }

    if (v >= 100 && v <= 150) {
        l = v + 50;
        $('#' + id + '_q2').css('color', otoh(Math.abs(((l - 200) / 100.0)) * 2));
    }


    if (v >= 100 && v <= 200) {
        if (v >= 150) $('#' + id + '_q2').css('color', otoh(0));
        v -= 100;
        $('#' + id + '_q3').css('color', otoh(Math.abs(((v) / 100.0))));
        $('#' + id + '_q1').css('color', otoh(0));
    }

}



function otoh(n) {
    n = n * 100;
    // o runs 0 - 100
    n = Math.abs(n - 50);
    m = 255 / 100;

    m = Math.round(n * m);
    return '#' + tohex(m) + tohex(m) + tohex(m)

}


function tohex(n) {
    var retval = '';
    if (n <= 0) {
        retval = '00';
        return retval;
    }
    var nt = n;
    while (n > 0) {
        var m = n;
        n = m >> 4;
        m = m % 16;
        var string = '';
        if (m < 10) string = '' + m; else {
            switch (m) {
                case 10:
                default:
                    string = 'A'
                    break;

                case 11:
                    string = 'B'
                    break;

                case 12:
                    string = 'C'
                    break;

                case 13:
                    string = 'D'
                    break;

                case 14:
                    string = 'E'
                    break;

                case 15:
                    string = 'F'
                    break;
            }
        }
        retval = string + retval;
    }
    if (nt < 16) retval = '0' + retval;
    return retval;
}







showNextBatch = function(nextGroup) {
    for (x = 0; x < groups[nextGroup].length; x++) { $('.pos' + groups[nextGroup][x]).customFadeIn('fast'); }
}

showMoreQuestions = function() {
    var nextGroup = currentGroup + 1;
    if (nextGroup >= maxGroups) nextGroup = 0;

    $('.finishReview').css('display', 'none');

    for (x = 0; x < groups[currentGroup].length; x++) {
        $('.pos' + groups[currentGroup][x]).customFadeOut('fast'); //('slide', { direction: 'left' }, 400);
    }

    setTimeout("showNextBatch(" + nextGroup + ")", 400);


    setTimeout("$('.finishReview').css('display', 'block');", 500);

    $('#qs' + currentGroup).customFadeOut('fast', function() { $('#qs' + nextGroup).customFadeIn('fast'); });

    currentGroup = nextGroup;

    if (!$.browser.msie) $.scrollTo(0, 500);
    else $.scroll(0);
}