////////////////////////////////////////////////
// Semi-peudo-code to generate two mortgage clocks:
// one for number of mortages, one for dollars.  This assumes clocks are 
// cumulative since 1990.
//
// 24 January 2010.  matt@wmbriggs.com
  
function mortgageValues(mortgvalues)
{

/////////////////////////////////////
// basic information

  var numsecondsyear = 365*24*60*60;
  var leapyearaddition = 24*60*60;  // 2012, 2016 leap years
  var today = new Date(); 
  if(today.getFullYear  % 4 == 0){
    // this gets us through 2016
     numsecondsyear = numsecondsyear + leapyearaddition;
  }

// historical information since 1990; the totals
  var nummortgages19902009 = 573149;
  var totalmortgagesdollars19902009 = 137943833.28*1000;

// these two sets of numbers are *projections* which should
// be replaced by the actual numbers after the year passes

  var nummortgages = new Array();
  nummortgages[0] = 116940; //2010
  nummortgages[1] = 118777; //2011
  nummortgages[2] = 124716; //2012
  nummortgages[3] = 130952; //2013
  nummortgages[4] = 137500; //2014
  nummortgages[5] = 144375; //2015
  nummortgages[6] = 151593; //2016
  var totalmortgagesdollars = new Array();
  totalmortgagesdollars[0] = 241.24 * 1000; //2010
  totalmortgagesdollars[1] = 230.37 * 1000; //2011
  totalmortgagesdollars[2] = 223.08 * 1000; //2012
  totalmortgagesdollars[3] = 215.56 * 1000; //2013
  totalmortgagesdollars[4] = 212.56 * 1000; //2014
  totalmortgagesdollars[5] = 225.08 * 1000; //2015
  totalmortgagesdollars[6] = 251.82 * 1000; //2016


/////////////////////////////////////
// algorithm
// this has to be adjusted each year
//need to calculate num seconds since midnight, 1 Jan

  var jan1 = new Date("January 1, 2010 00:00:00")
  var todaytime = today.getTime();
  var secondssince1jan = (todaytime - jan1) / 1000;

//Calculate index for the array
  yearidx=today.getFullYear()-2010;
  nummortgagespersecond = nummortgages[yearidx]/numsecondsyear;
  nummortgagesdollarspersecond = nummortgages[yearidx]*totalmortgagesdollars[yearidx]/numsecondsyear;



/////////////////////////////////////////////////
// what goes on the clocks: assuming clocks are cumulative since 1990
// 
// number clock starts at 573,149 and by 2016 will go to about 1,500,000; thus 7 digits needed
//
// dollar clock starts at about $130,000,000,000
// and by 2016 will go to about $350,000,000,000; thus 12 digits needed
//
// what to display on clock NOW
// (you should probably round)
// this assumes the clock is cumlative since 1990
// if *not*, remove the first argument in each sum on right hand side
  mortgvalues.clocknummortgages = nummortgages19902009 + secondssince1jan * nummortgagespersecond;
  mortgvalues.clocknummortgagesdollars = totalmortgagesdollars19902009 + secondssince1jan * nummortgagesdollarspersecond;

  return mortgvalues;
}