

//###############################

function show440(id) {
	if (document.getElementById) {
		 document.getElementById(id).style.display="inline";
	}
	else if (document.all) {
		document.all[id].style.display="inline";
	} 
	else if (document.layers) {
		document.layers[id].display="inline";
	}
} 

function hide440(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display="none";
		//document.getElementById(id).style.visibility='hidden';
	} 
	else if (document.all) {
		document.all[id].style.display="none";
	} 
	else if (document.layers) {
		document.layers[id].display="none";
	}
} 


function SwitchLang(id,lang){
	if(lang=='en')
		{
		rlang='fr';
	}
	else{
		rlang='en';
	}
	
	hide440(id+rlang);
	show440(id+lang);
}

function ShowLang(lang){
	SwitchLang('title_',lang);
	SwitchLang('help_',	lang);
	SwitchLang('sw_',	lang);
	SwitchLang('days_',	lang);
	SwitchLang('hours_',lang);

}
//########################################################


function UpdateUrl(id){
	url='http://play.wxop.com/countdown/?d='+encodeURI(finalDate);
	if (document.getElementById) {
		document.getElementById(id).value=url;
	}
	else if (document.all) {
		document.all[id].value=url;
	} 
	else if (document.layers) {
		document.layers[id].value=url;
	}

}


// preload images
var clock1 = new Array();
for(i=0; i < 10; i++) {
	clock1[i] = new Image();
	clock1[i].src = "img/" + i + "1.gif"; // take gif out of source name for use with abc
}
var clock2 = new Array();
for(i=0; i < 10; i++) {
	clock2[i] = new Image();
	clock2[i].src = "img/" + i + "2.gif"; // take gif out of source name for use with abc
}
var clock3 = new Array();
for(i=0; i < 11; i++) {
	clock3[i] = new Image();
	clock3[i].src = "img/" + i + "3.gif"; // take gif out of source name for use with abc
}

var countercd	=	1;
var counterd	=	1;
var counterdd	=	1;
var counterh	=	1;
var counterhh	=	1;
var counterm	=	1;
var countermm	=	1;
var counters	=	1;
var counterss	=	1;

var finalDate='';

function countdown(date_id) {
	var indate='';
	if (document.getElementById) {
		indate=document.getElementById(date_id).value;
	}
	else if (document.all) {
		indate=document.all[date_id].value;
	} 
	else if (document.layers) {
		indate=document.layers[date_id].value;
	}
	finalDate=indate;
	//alert("date "+indate);
	
	if( (indate == null) || (indate == "" ) ){
		indate="January 1, 2007 00:00:00";
	}
	path = "img/";
	s	=	1;	//initialize seconds
	// now
	var now = new Date();
	var then = new Date(indate);

	var difference = new Date();
	difference.setTime(Math.abs(then.getTime() - now.getTime()));
	timeDifference = difference.getTime();

	// dRemain	=	Math.ceil((then.getTime() - now.getTime()) / (one_day));

	dRemain	=	Math.floor(timeDifference / (1000 * 60 * 60 * 24));
	timeDifference -= dRemain * (1000 * 60 * 60 * 24);
	hRemain = Math.floor(timeDifference / (1000 * 60 * 60)); 
	timeDifference -= hRemain * (1000 * 60 * 60);
	mRemain = Math.floor(timeDifference / (1000 * 60)); 
	timeDifference -= mRemain * (1000 * 60);
	sRemain = Math.floor(timeDifference / 1000); 
	timeDifference -= sRemain * 1000;
	
	var o=0; 
	while (dRemain > 9) {
		o++;
		dRemain = dRemain-10
	}
	if(o > 9){
		var n=0; 
		while (o > 9) {
			n++;
			o = o-10
		}
		if (document.cday440.src.indexOf(clock3[n].src) < 0 && countercd < 4) {
			document.cday440.src = eval("clock" + (countercd) + "[" + n + "].src");
			countercd++;
		} else {
			document.cday440.src = clock3[n].src;
			countercd=1;
		} 
		
	}
	else{
		document.cday440.src =clock3[10].src; //empty gif
		countercd=1;
	}
	
	if (document.day440.src.indexOf(clock3[o].src) < 0 && counterd < 4) {
		document.day440.src = eval("clock" + (counterd) + "[" + o + "].src");
		counterd++;
	} else {
		document.day440.src = clock3[o].src;
		counterd=1;
	} 

	if (document.dayday440.src.indexOf(clock3[dRemain].src) < 0 && counterdd < 4) {
		document.dayday440.src = eval("clock" + (counterdd) + "[" + dRemain + "].src");
		counterdd++;
	} else {
		document.dayday440.src = clock3[dRemain].src;
		counterdd=1;
	}

	var p=0; 
	while (hRemain > 9) {
		p++;
		hRemain = hRemain-10
	} 

	if (document.hour440.src.indexOf(clock3[p].src) < 0 && counterh < 4) {
		document.hour440.src = eval("clock" + (counterh) + "[" + p + "].src");
		counterh++;
	} else {
		document.hour440.src = clock3[p].src;
		counterh=1;
	} 

	if (document.hourhour440.src.indexOf(clock3[hRemain].src) < 0 && counterhh < 4) {
		document.hourhour440.src = eval("clock" + (counterhh) + "[" + hRemain + "].src");
		counterhh++;
	} else {
		document.hourhour440.src = clock3[hRemain].src;
		counterhh=1;
	}

	var q=0; 
	while (mRemain > 9) { 
		q++; 
		mRemain = mRemain-10
	} 

	if (document.minute440.src.indexOf(clock3[q].src) < 0 && counterm < 4) {
		document.minute440.src = eval("clock" + (counterm) + "[" + q + "].src");
		counterm++;
	} else {
		document.minute440.src = clock3[q].src;
		counterm=1;
	} 
	if (document.minuteminute440.src.indexOf(clock3[mRemain].src) < 0 && countermm < 4) {
		document.minuteminute440.src = eval("clock" + (countermm) + "[" + mRemain + "].src");
		countermm++;
	} else {
		document.minuteminute440.src = clock3[mRemain].src;
		countermm=1;
	}

	var r=0; 
	while (sRemain > 9) {
		r++;
		sRemain = sRemain-10
	} 
	if (document.second440.src.indexOf(clock3[r].src) < 0 && counters < 4) {
		document.second440.src = eval("clock" + (counters) + "[" + r + "].src");
		counters++;
	} else {
		document.second440.src = clock3[r].src;
		counters=1;
	} 
	if (document.secondsecond440.src.indexOf(clock3[sRemain].src) < 0 && counterss < 4) {
		document.secondsecond440.src = eval("clock" + (counterss) + "[" + sRemain + "].src");
		counterss++;
	} else {
		document.secondsecond440.src = clock3[sRemain].src;
		counterss=1;
	}
	setTimeout("countdown('"+date_id+"')",20);

}
