

function makeArray(total, steps)
{
     if (typeof steps == "undefined")
     {
          steps = 100;
     }
     var arr = new Array();
     for (i = 0; i <= steps; i++)
     {
          arr[arr.length] = Math.ceil(Math.random() * parseInt(total));
     }

     arr.sort(function(a,b){return a - b});
     arr[arr.length] = total;
     return arr;
}


function counter(arr, id)
{

     $(id).text(arr.shift());

     if (arr.length > 0)
     {
          setTimeout(function() {counter(arr,id)}, 10);
     }

}


function updateTotal(selection)
{
     var request = "total.php?selection=selection";
     $.getJSON( request, function(response) { doUpdate(response, '#total'  + selection);});

}

function doUpdate(response, id)
{
     $(id).text(response.total) ;
}


function getTotal(steps, selection)
{
     var request = "total.php?selection=" + selection;
     $.getJSON( request, function(response){ counter(makeArray(response.total, steps), '#total' + selection);});
}



$(document).ready(function()
                  {
                      getTotal(100, 'handsoff');
                      getTotal(100, 'HC09');
                       //setInterval(updateTotal, 120000 );
                  });


