
var curamount=0;
var curscale=0;   
var curunit="";   	  
var geographicscale=1; 


function set_unit (altscale, altunit) {
  curscale = altscale;
  curunit = altunit;
}


function calc_amount () {

  var totalms       = 31556952000;
  var initialsharks= 0;
  var totalsharks  = 100000000 - initialsharks;
  var rateperms     = totalsharks / totalms;
  
  var curdate = new Date ();
  var ThisYear=curdate.getFullYear()
  var startofyear = new Date ("Jan 01, " + ThisYear);
  
  var diff = curdate - startofyear;
  
  if (diff < 0) {
    alert ("bite-back uses your computers date to calculate the number of sharks killed this year. "+
           "Yours must be wrong!");
  }
  curamount = (initialsharks + diff * rateperms) * geographicscale;
}


function number_str (n) {

  var x = n.toString ();
  var dot = x.lastIndexOf ('.');
  x = x.substr (0, dot);
  var l = x.length;
  var res = "";
  for (l -= 3; l > 0; l -= 3) {
    res = "," + x.substr (l, 3) + res;
  }
  res = x.substr (0, l+3) + res;
  return res;
}


function inc_totals_at_rate(rate) {

 
  calc_amount ();


  document.getElementById ("raw").firstChild.nodeValue = 
  " " + number_str(curamount);


  try {
    if (curscale != 0) {
  	    var altamount = curamount / curscale;
  	    document.getElementById ("alt").firstChild.nodeValue =
  	    number_str(altamount) + curunit;
    }
    else {
  	    document.getElementById ("alt").firstChild.nodeValue = "";
    }
  } catch (e)
  {

  }


  setTimeout('inc_totals_at_rate('+rate+');', rate);

}
function inc_totals_at_rate2(rate) {


  calc_amount ();


  document.getElementById ("raw").firstChild.nodeValue = 
  " " + number_str(curamount);

  try {
    if (curscale != 0) {
  	    var altamount = curamount / curscale;
  	    document.getElementById ("alt").firstChild.nodeValue =
  	    number_str(altamount) + curunit;
    }
    else {
  	    document.getElementById ("alt").firstChild.nodeValue = "";
    }
  } catch (e)
  {

  }


  setTimeout('inc_totals_at_rate('+rate+');', rate);

}

function inc_totals ()
{
  inc_totals_at_rate (50);
}