var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var old_dday=new String("000"), old_dhour = new String("00"), old_dmin = new String("00"), old_dsec = new String("00");

function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()

	if (todayy < 1000) todayy+=1900
	
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

dday 	= (dday		< 10 ? '0' + dday 	: dday).toString();
dhour 	= (dhour	< 10 ? '0' + dhour 	: dhour).toString();
dmin 	= (dmin		< 10 ? '0' + dmin 	: dmin).toString();
dsec 	= (dsec		< 10 ? '0' + dsec 	: dsec).toString();

refresh_clock(dday,dhour,dmin,dsec);

old_dday  = dday;
old_dhour = dhour;
old_dmin  = dmin;
old_dsec  = dsec;

setTimeout("countdown(theyear,themonth,theday)",1000)
}

function refresh_clock(d,h,m,s) {	
var clock_div = document.getElementById('compte_a_rebours');
var html = '<span class="compteur">';

	for (var i = 0; i<d.length; i++) {
	html += '<span id="d' + i + '" class="compteur' + d.charAt(i) + ' chiffre textimage">' + d.charAt(i) + '</span>';	
	}

html += '<span id="jour-' + (d>1?'plur':'sing') + '" class="unite textimage">&nbsp;days&nbsp;</span></span>\n';

html += '<span class="compteur"><span id="h0" class="compteur' + h.charAt(0) + ' chiffre textimage">' + h.charAt(0) + '</span><span id="h1" class="compteur'  + h.charAt(1) +  ' chiffre textimage">' + h.charAt(1) + '</span><span id="heure-' + (h>1?'plur':'sing') + '" class="unite textimage">&nbsp;hours&nbsp;</span></span>\n';

html += '<span id="m0" class="compteur"><span id="h1" class="compteur' + m.charAt(0) + ' chiffre textimage">' + m.charAt(0) + '</span><span id="m1" class="compteur'  + m.charAt(1) +  ' chiffre textimage">' + m.charAt(1) + '</span><span id="minute-' + (m>1?'plur':'sing') + '" class="unite textimage">&nbsp;minutes&nbsp;</span></span>\n';

html += '<span id="s0" class="dernier"><span class="compteur' + s.charAt(0) + ' chiffre textimage">' + s.charAt(0) + '</span><span id="s1"  class="compteur'  + s.charAt(1) +  ' chiffre textimage">' + s.charAt(1) + '</span><span id="seconde-' + (s>1?'plur':'sing') + '" class="unite textimage">&nbsp;seconds&nbsp;</span></span>\n';

clock_div.innerHTML = html;


	if (old_dday != d && old_dday.length == d.length) {
		for (var i=0; i<d.length; i++) {
			if (old_dday.charAt(i) != d.charAt(i) ) new Effect.Opacity('d'+i, {duration:0.5, from:0.5, to:1.0});
		}
	}
	if (old_dhour != h && old_dhour.length == h.length) {
		if (old_dhour.charAt(0) != h.charAt(0) ) new Effect.Opacity('h0', {duration:0.5, from:0.5, to:1.0});
		if (old_dhour.charAt(1) != h.charAt(1) ) new Effect.Opacity('h1', {duration:0.5, from:0.5, to:1.0});
	}
	if (old_dmin != m && old_dmin.length == m.length) {
		if (old_dmin.charAt(0) != m.charAt(0) ) new Effect.Opacity('m0', {duration:0.5, from:0.5, to:1.0});
		if (old_dmin.charAt(1) != m.charAt(1) ) new Effect.Opacity('m1', {duration:0.5, from:0.5, to:1.0});
	}
	if (old_dsec != s && old_dsec.length == s.length) {
		if (old_dsec.charAt(0) != s.charAt(0) ) new Effect.Opacity('s0', {duration:0.5, from:0.5, to:1.0});
		if (old_dsec.charAt(1) != s.charAt(1) ) new Effect.Opacity('s1', {duration:0.5, from:0.5, to:1.0});
	}
}
