function MM_preloadImages() {
  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];}
	}
}

// This is the HTML table

document.writeln('<table width=\"214\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#666666\">');
document.writeln('<tr><td class=\"texto\" bgcolor=\"#000000\">&nbsp;Countdown</td></tr>');
document.writeln('</table>');
document.writeln('<img src=\"http://www.terra.com/t.gif\" width=1 height=1 border=0><br>');
document.writeln('<table width=\"214\" height=\"35\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"img/back_countdown.gif\">');
document.writeln('<tr><td>');
document.writeln('<img src=\"http://www.terra.com/t.gif\" alt=\"\" width=\"10\" height=\"35\" border=\"0\" align=\"left\">');
document.writeln('<img src=\"http://www.terra.com/t.gif\" width=1 height=12 border=0><br>');
document.writeln('<img name=\"countdown_d10\" src=\"img/0.gif\" width=\"13\" height=\"14\" alt=\"\" border=\"0\" align=\"middle\">');
document.writeln('<img src=\"img/0.gif\" alt=\"\" name=\"countdown_d1\" id=\"countdown_d1\" width=\"13\" height=\"14\" border=\"0\" align=\"middle\">');
document.writeln('<b>d&iacute;as y</b>&nbsp;');
document.writeln('<img name=\"countdown_h10\" src=\"img/0.gif\" width=\"13\" height=\"14\" alt=\"\" border=\"0\" align=\"middle\">');
document.writeln('<img name=\"countdown_h1\" src=\"img/0.gif\" width=\"13\" height=\"14\" alt=\"\" border=\"0\" align=\"middle\">');
document.writeln('<img src=\"img/count_dots.gif\" alt=\"\" width=\"6\" height=\"14\" border=\"0\" align=\"middle\">');
document.writeln('<img name=\"countdown_m10\" src=\"img/0.gif\" width=\"13\" height=\"14\" alt=\"\" border=\"0\" align=\"middle\">');
document.writeln('<img name=\"countdown_m1\" src=\"img/0.gif\" width=\"13\" height=\"14\" alt=\"\" border=\"0\" align=\"middle\">');
document.writeln('<img src=\"img/count_dots.gif\" alt=\"\" width=\"6\" height=\"14\" border=\"0\" align=\"middle\">');
document.writeln('<img name=\"countdown_s10\" src=\"img/0.gif\" width=\"13\" height=\"14\" alt=\"\" border=\"0\" align=\"middle\">');
document.writeln('<img name=\"countdown_s1\" src=\"img/0.gif\" width=\"13\" height=\"14\" alt=\"\" border=\"0\" align=\"middle\">');
document.writeln('</td></tr></table>');



// Image-based countdown script  v1.0
// http://www.dithered.com/javascript/countdown/index.html
// code by Chris Nott (chris@dithered.com)

var endDate;
var countdownGraphics;


// Preload number graphics
function countdownSetGraphics(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9) {
	countdownGraphics = new Array(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9);
	preloadImages(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9);
}


// Image preloader
function preloadImages() {
	document.preload = new Array();
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
			document.preload[i] = new Image();
			document.preload[i].src = preloadImages.arguments[i];
		}
	}
}


// Initialize and start the countdown
function countdownInit(year, month, day, hour, minute, second) {

	// set date to countdown to
	endDate = new Date(year, month - 1, day, ( (hour) ? hour : 0), ( (minute) ? minute : 0), ( (second) ? second : 0));
	
	// start countdown
	countdownUpdate();
	setInterval('countdownUpdate()', 1000);
}


// Update the countdown display
function countdownUpdate() {
	var separator = ':';
	
	// calculate the time until countdown end date
	var now = new Date();
	var difference = endDate - now;
	
	// decompose difference into days, hours, minutes and seconds parts
	var days    = parseInt(difference / 86400000) + '';
	var hours   = parseInt((difference % 86400000) / 3600000) + '';
	var minutes = parseInt((difference % 3600000) / 60000) + '';
	var seconds = parseInt((difference % 60000) / 1000) + '';
	
	// negative values should be set to 0
	// single digit values should have a '0' prepended to them
	if (isNaN(days) || days.charAt(0) == '-') days = '0000';
	else if (days.length == 1) days = '000' + days;
	else if (days.length == 2) days = '00' + days;
	else if (days.length == 3) days = '0' + days;
	if (isNaN(hours) || hours.charAt(0) == '-') hours = '00';
	else if (hours.length == 1) hours = '0' + hours;
	if (isNaN(minutes) || minutes.charAt(0) == '-') minutes = '00';
	else if (minutes.length == 1) minutes = '0' + minutes;
	if (isNaN(seconds) || seconds.charAt(0) == '-') seconds = '00';
	else if (seconds.length == 1) seconds = '0' + seconds;
	
	// change countdown graphics
	if (document.images['countdown_d1000']) document.images['countdown_d1000'].src = countdownGraphics[parseInt(days.charAt(0))];
	if (document.images['countdown_d100']) document.images['countdown_d100'].src = countdownGraphics[parseInt(days.charAt(1))];
	if (document.images['countdown_d10']) document.images['countdown_d10'].src = countdownGraphics[parseInt(days.charAt(2))];
	if (document.images['countdown_d1']) document.images['countdown_d1'].src = countdownGraphics[parseInt(days.charAt(3))];
	if (document.images['countdown_h10']) document.images['countdown_h10'].src = countdownGraphics[parseInt(hours.charAt(0))];
	if (document.images['countdown_h1']) document.images['countdown_h1'].src = countdownGraphics[parseInt(hours.charAt(1))];
	if (document.images['countdown_m10']) document.images['countdown_m10'].src = countdownGraphics[parseInt(minutes.charAt(0))];
	if (document.images['countdown_m1']) document.images['countdown_m1'].src = countdownGraphics[parseInt(minutes.charAt(1))];
	if (document.images['countdown_s10']) document.images['countdown_s10'].src = countdownGraphics[parseInt(seconds.charAt(0))];
	if (document.images['countdown_s1']) document.images['countdown_s1'].src = countdownGraphics[parseInt(seconds.charAt(1))];
}


countdownSetGraphics('img/0.gif', 'img/1.gif', 'img/2.gif', 'img/3.gif', 'img/4.gif', 'img/5.gif', 'img/6.gif', 'img/7.gif', 'img/8.gif', 'img/9.gif');
countdownInit(2003, 6, 27,23,00,00);


