<!--
//----- 11-20-02, 11-21-02

var contentType = 1;         // Default Text=1, images=0

//----- If dot, then match for image file types...
var tvar = theItems[0];
if ( tvar.indexOf(".") + 1 )
{
//----- If ends in .jpg or .gif, must be an image type file...
        if ( tvar.match(/\.(jpg|gif)$/) ) contentType = 0;
}

var n        = theItems.length;
var upperbnd = n - 1;           // Upper bound slot in array
var lowerbnd = 0;               // Lower bound slot

var sequence = new Array(n);
build_seq(n);

if ( ! contentType )
{
//----- If images, loadup the prefetch buffer...
        preLoadImages(n);
}

var count     = 0;
var errors    = 0;
var whichItem = 0;
var seq_cnt   = 0;
var direction = 0;

function getMatch()
{
        var mychecked;

        for (var i = 0; i < n; i++)
        {
//----- Find out which one has been checked... and exit loop
                if (document.game.choices[i].checked)
                {
                        mychecked = i;
                        break;
                }
        }

        if ( whichItem == mychecked)
        {
//----- Ack the correct choice, could be alot more...
// alert("OK, you got it!");
                
//----- Check the box if OK and mark as done...
                document.game.done[whichItem].checked = 1;
        }
        else
        {
//----- Move the dot to the correct choice...
                document.game.choices[whichItem].checked = 1;
                alert("Correct choice is shown...");
                errors++;
                document.game.errors.value = errors;
        }

//----- Always inc event counter... and display
        count++;
        document.game.counter.value = count;
}

function getNext()
{
//----- Select a random choice to display in window...
        whichItem = sequence[seq_cnt];
        (direction) ? seq_cnt++ : seq_cnt-- ;

//----- Reset to top of array
        if (seq_cnt > upperbnd) seq_cnt = 0;

//----- Reset to bottom of array
        if (seq_cnt < 0) seq_cnt = upperbnd;

//----- ... now we are done.
        if (count > upperbnd)
        {
                document.game.counter.value = "Done!";
                return;
        }

//----- contentType is either text=1 or images=0...
        if ( contentType )
        {
                document.game.myDisplay.value = theItems[whichItem];
        }
        else
        {
                document.myImages.src = theItems[whichItem];
        }
}

function clearChoices()
{
//----- Clear the last item selected... before the next choosing
        document.game.choices[whichItem].checked = 0;
}

function write_it()
{
//----- Write in the radio buttons and the descriptions...
        var radioButtons = '<input type="radio" name="choices"> ';
        var checkBoxes   = ' <input type="checkbox" name="done"> ';

        for (var x = 0; x < n; x++)
        {
                document.write("<li> " + radioButtons + checkBoxes + theDesc[x] + ' <br>');
        }
}

function build_seq(max)
{
//----- Load up this sequencing array...
        for (var j = 0; j < max; j++)
        {
                sequence[j] = j;
        }
}

function clearAll()
{
//-----Clear all check boxes...
        for (var k = 0; k < n; k++) document.game.done[k].checked = 0;

//----- Reset all counters...
        seq_cnt   = 0;
        count     = 0;
        errors    = 0;
        whichItem = 0;

//----- Reset window field displays...
        document.game.reset();

//----- Below does not really clear the screen! More work...
        if ( ! contentType ) document.myImages.src = "";
}

function scramble()
{
//----- Rearrange an ordered list to a scrambled list...
//      Do only once at the start of each "session:
        var tmp   = "";
        var cnt   = 0;
        var mid   = 0;

        mid = Math.round( (n/2) );

        for (var y = 0; y < mid; y++)
        {
                for (var x = 0; x < n; x++)
                {
                        if (sequence[cnt+1])
                        {
                                tmp             = sequence[cnt];
                                sequence[cnt]   = sequence[cnt+1];
                                sequence[cnt+1] = tmp;
                        }
                        else break;
                        cnt = cnt + 2;
                }
//----- Shift left and append first to end...
                tmp = sequence[0];
                for (x = 1; x < n; x++) sequence[x-1] = sequence[x];
                sequence[n-1] = tmp;
        }

//----- Derive random number from the clock in seconds
        var now  = new Date();
        var secs = Number(now.getSeconds());
        seq_cnt  = 2;                   // Assumes at least 2 answers

        if (secs > 9) secs    = Math.round(secs % 10);
        if (secs > 0) seq_cnt = Math.round( (secs/10) * (n - 1) );

//----- Then see if number is odd or even and go by that!
        ( seq_cnt % 2 ) ? direction = 1 : direction = 0;
}

function preLoadImages(max)
{
//----- Load the prefetch buffer...
        var preBuffer = new Array()

        for (var i = 0; i < max; i++)
        {
                preBuffer[i]     = new Image();
                preBuffer[i].src = theItems[i];
        }
}

function setDisplayType()
{
//----- Write into the doc so that you have the matching choice..
        var textType  = '<input type="text" name="myDisplay" value="">';
        var imageType = '<img name="myImages" width="100" height="130">';

        (contentType) ? document.write(textType) : document.write(imageType);
}

//-->
