function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
} 



Date.prototype.getDOY = function()	{
							var onejan = new Date(this.getFullYear(),0,1);
							return Math.floor((this - onejan) / 86400000);
						}

function addCommas(nStr)
{
	nStr += '';
	var x = nStr.split('.');
	var x1 = x[0];
	var x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

// This function copyright free courtesy of heritage action
function startCount(){
	finds = new Array();

	// Estimate of overall finds not reported at start of January 2007, since 1975:
	finds['startof2007'] = 9797008;

	// Estimate finds found Since 1997 (the start of the Portable Antiquities Scheme)
	finds['startofPAS'] = 2925215;

	// Estimate of finds found per hour in daylight time
	finds['daytimeperhour'] = 60;
	finds['nighttimeperhour'] = 6;

	var nighttimehours = 12;
	var daytimehours = 12;

	finds['peryear']  = 365 * ( ( nighttimehours * finds['nighttimeperhour'] ) + ( daytimehours * finds['daytimeperhour'] ) );

	// What day of the year it was at the last midnight
	var now = new Date();
	var nowday = now.getDOY();

	// What date is 2007, get round differences between IE and firefox.
	var date2007 = new Date();
	date2007.setFullYear(2007,0,1);
	
	// How many years since 2007
	var nowyear = now.getYear() - date2007.getYear();

	// How many hours and minutes since last midnight
	var nowhours = now.getHours();
	var nowminutes = now.getMinutes();

	var nownighttimehours = 0;
	var nowdaytimehours = 0;
	var minutes = 0;

	// work out how many finds gone so far today
	if( nowhours < 8 ){
		nownighttimehours = nowhours;
		minutes = Math.floor( nowminutes / ( 60 / finds['nighttimeperhour'] ) );
	}else if( nowhours >= 20 ){
		nownighttimehours = nowhours - 12;
		nowdaytimehours = 12;
		minutes = Math.floor( nowminutes / ( 60 / finds['nighttimeperhour'] ) );
	}else{
		nownighttimehours = 8;
		nowdaytimehours = nowhours - 8;
		minutes = Math.floor( nowminutes / ( 60 / finds['daytimeperhour'] ) );
	}

	finds['today'] = ( ( nownighttimehours * finds['nighttimeperhour'] ) + ( nowdaytimehours * finds['daytimeperhour'] ) ) + minutes;
	finds['thisyear'] = ( nowday * ( ( nighttimehours * finds['nighttimeperhour'] ) + ( daytimehours * finds['daytimeperhour'] ) ) ) +  finds['today'];
	finds['pas'] = finds['startofPAS'] + ( nowyear * finds['peryear'] ) + finds['thisyear'];
	finds['since1975'] = finds['startof2007'] + ( nowyear * finds['peryear'] ) + finds['thisyear'];

	// Display the number of finds
	//var countSpan = document.getElementById('countspan');
	//countSpan.innerHTML = finds['total'].toString().substr(0,2) + "," + finds['total'].toString().substr(2,3) + "," + finds['total'].toString().substr(5,3);

	if(document.getElementById('counttoday')){
		var counttoday = document.getElementById('counttoday');
		counttoday.innerHTML = addCommas(finds['today']);
	}
	if(document.getElementById('countthisyear')){
		var countthisyear = document.getElementById('countthisyear');
		countthisyear.innerHTML = addCommas(finds['thisyear']);
	}
	if(document.getElementById('countpas')){
		var countpas = document.getElementById('countpas');
		countpas.innerHTML = addCommas(finds['pas']);
	}
	if(document.getElementById('countsince1975')){
		var countsince1975 = document.getElementById('countsince1975');
		countsince1975.innerHTML = addCommas(finds['since1975']);
	}
	if(document.getElementById('countLHM')){
		var countsince1975 = document.getElementById('countLHM');
		countsince1975.innerHTML = addCommas(finds['since1975']);
	}

    setTimeout('startCount()', 60000);
}

