c1 = new Image(); c1.src = "numerals/a1.gif";
c2 = new Image(); c2.src = "numerals/a2.gif";
c3 = new Image(); c3.src = "numerals/a3.gif";
c4 = new Image(); c4.src = "numerals/a4.gif";
c5 = new Image(); c5.src = "numerals/a5.gif";
c6 = new Image(); c6.src = "numerals/a6.gif";
c7 = new Image(); c7.src = "numerals/a7.gif";
c8 = new Image(); c8.src = "numerals/a8.gif";
c9 = new Image(); c9.src = "numerals/a9.gif";
c0 = new Image(); c0.src = "numerals/a0.gif";
cb = new Image(); cb.src = "numerals/cb.gif";
onePix = new Image(); onePix.src = "numerals/clear.gif";

function GetCount(){

	dateNow = new Date();	//grab current date
	amount = dateFuture.getTime() - dateNow.getTime();	//calc milliseconds between dates

	// time is already past
	if(amount < 0){
			document.getElementById('countbox').innerHTML="00:00:00";
	}
	// date is still good
	else{
			days=0;hours=0;mins=0;secs=0;out="";

			amount = Math.floor(amount/1000);	//kill the "milliseconds" so just secs

			days = Math.floor(amount/86400);	//days
			amount = amount % 86400;

			hours = Math.floor(amount/3600);	//hours
			amount = amount % 3600;

			mins = Math.floor(amount/60);	//minutes
			amount = amount % 60;

			secs = Math.floor(amount);	//seconds

			if(days != 0){	out += days +" day"+((days!=1)?"s":"")+", ";	}
			if(days != 0 || hours != 0){	out += hours +" hour"+((hours!=1)?"s":"")+", ";	}
			if(days != 0 || hours != 0 || mins != 0){	out += mins +" minute"+((mins!=1)?"s":"")+", ";	}
			out += secs +" seconds";
			document.getElementById('countbox').innerHTML=out;

			setTimeout("GetCount()", 1000);
	}
}

function extract(d,h,m,s,type){
	if (!document.images) return;
	if(d < 1){
		document.images.a.src = onePix.src;
		document.images.a.width = 1;
		document.images.b.src = onePix.src;
		document.images.b.width = 1;
		document.images.c.src = onePix.src;
		document.images.c.width = 1;
		document.images.d.src = onePix.src;
		document.images.d.width = 1;
	}
	else{
		if(d <= 9){
		document.images.a.src = onePix.src;
		document.images.a.width = 1;
		document.images.b.src = onePix.src;
		document.images.b.width = 1;
		document.images.c.src = eval("c"+d+".src");
		}
		else{
			if(d < 100){
				document.images.a.src = onePix.src;
				document.images.a.width = 1;
				document.images.b.src = eval("c"+Math.floor(d/10)+".src");
				document.images.c.src = eval("c"+(d%10)+".src");
			}
			else{
				var numHundreds = Math.floor(d/100);
				document.images.a.src = eval("c"+numHundreds+".src");
				var numTens = d - (numHundreds*100);
				document.images.b.src = eval("c"+Math.floor(numTens/10)+".src");
				document.images.c.src = eval("c"+(d%10)+".src");
			}

		}
	}
	if(h <= 9){
	document.images.e.src = c0.src;
	document.images.f.src = eval("c"+h+".src");
	}
	else{
	document.images.e.src = eval("c"+Math.floor(h/10)+".src");
	document.images.f.src = eval("c"+(h%10)+".src");
	}
	if(m <= 9){
	document.images.h.src = c0.src;
	document.images.i.src = eval("c"+m+".src");
	}
	else{
	document.images.h.src = eval("c"+Math.floor(m/10)+".src");
	document.images.i.src = eval("c"+(m%10)+".src");
	}
	if(s <= 9){
	document.k.src = c0.src;
	document.images.l.src = eval("c"+s+".src");
	}
	else{
	document.images.k.src = eval("c"+Math.floor(s/10)+".src");
	document.images.l.src = eval("c"+(s%10)+".src");
	}
}

function showCountdown(){
	if (!document.images){
		return;
	}
	var today = new Date();
	var target = new Date(theTargetDate);
	var timediff = (  target.getTime()-today.getTime()  );
	var oneMinute = 1000*60 //minute unit in seconds
	var oneHour = 1000*60*60 //hour unit in seconds
	var oneDay = 1000*60*60*24 //day unit in seconds
	var dayfield = Math.floor(timediff/oneDay);
	var hourfield = Math.floor((timediff-dayfield*oneDay)/oneHour);
	var minutefield = Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute);
	var secondfield = Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute)/1000);

	if(timediff < 0){
		document.location.href="http://countdown.onlineclock.net/alarm.html";
	}
	else{
		extract(dayfield,hourfield, minutefield, secondfield);
		setTimeout("showCountdown()", 1000);
	}

}

function changeImageSize(widthA,heightA,widthB,heightB){
	//image array 0-8
	for (i = 1; i <= 12; i++){	
		//if we're showing clear.gif, make sure it's 1x1 pixel
		if(document.images[i].src==onePix.src){
			document.images[i].width = 1;
			document.images[i].height = 1;
		}
		//small colon images
		else if( (i==4)||(i==7)||(i==10) ){
			document.images[i].width = widthB;
			document.images[i].height = heightB;
		}
		//normal numbers
		else{
			document.images[i].width = widthA;
			document.images[i].height = heightA;
		}
	}
}

function addLeadingZero(x) {
      return ((x<0 || x>9) ?"":"0") + x;
}


