/* this code copyright 2007 Tom Churm, all rights reserved, no copying without permission */
//if (top.location != document.location) top.location = document.location;

c1 = new Image(); c1.src = "numerals2/c1.gif";
c2 = new Image(); c2.src = "numerals2/c2.gif";
c3 = new Image(); c3.src = "numerals2/c3.gif";
c4 = new Image(); c4.src = "numerals2/c4.gif";
c5 = new Image(); c5.src = "numerals2/c5.gif";
c6 = new Image(); c6.src = "numerals2/c6.gif";
c7 = new Image(); c7.src = "numerals2/c7.gif";
c8 = new Image(); c8.src = "numerals2/c8.gif";
c9 = new Image(); c9.src = "numerals2/c9.gif";
c0 = new Image(); c0.src = "numerals2/c0.gif";
cb = new Image(); cb.src = "numerals2/cb.gif";
onePix = new Image(); onePix.src = "numerals2/clear.gif";

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://www.ibd.it/fismad.htm";
	}
	else
	{
		extract(dayfield,hourfield, minutefield, secondfield);
		setTimeout("showCountdown()", 1000);
	}
}

function changeImageSize(widthA,heightA,widthB,heightB) {
	//image array 0-8
	for (i = 0; i <= 11; 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==3)||(i==6)||(i==9) )
		{
			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;
}

var weekendDate = "";
var arrayMonths = new Array(
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" );
var weekdays = new Array( "sun","mon","tue","wed","thu","fri","sat" );
var longWeekdays = new Array(
"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" );
var objToday = null;

function getCurrentWeekEnding() {
  var objToday = new Date();
  var millis = objToday.valueOf();
  var weekday = objToday.getDay();
  
  //find out if it's already the weekend:
  if(weekday==6)
  {
  	//it's a saturday
  }
  else if(weekday==0)
  {
  	//it's a sunday
  }

  switch( weekday ) 
  {
    case 0:
      millis += ( 86400000 * 6 );
      break;
    case 1:
      millis += ( 86400000 * 5 );
      break;
    case 2:
      millis += ( 86400000 * 4 );
      break;
    case 3:
      millis += ( 86400000 * 3 );
      break;
    case 4:
      millis += ( 86400000 * 2 );
      break;
    case 5:
      millis += 86400000;
      break;
    case 6:
      millis += ( 86400000 * 7 );
      break;
  }
  
  var weekEndingDate = new Date( millis );
  var month = weekEndingDate.getMonth();
  var dayOfMonth = weekEndingDate.getDate();
  var year = weekEndingDate.getFullYear();
			
  for( var i = 0; i < arrayMonths.length; i++ ) {
				
    if( i == month ) {
      month = arrayMonths[ i ];
    }
  }
  weekendDate = month + " " + dayOfMonth + ", " + year + " 00:00:00";
  
  return( weekendDate );
}
