/*
Date: 03/12/2008
Created by: www.christopherjones.com.au
Precis: Ticker counting down to Earth Hour 2010
Instructions: Add the appropriate script tag where you would like the countdown widget to appear.

160 x 140 pixel version (with linked Earth Hour logo)


160 x 40 pixel version (no Earth Hour logo)

*/
var earthHour = new Date("March 27, 2010 20:30:00");
var scripts = document.getElementsByTagName('script');
var index = scripts.length-1;
var script = scripts[index];
var showlogo = script.src.replace(/^[^\?]+\??/,'');
// -----------------------------------------------------------------------------------------
function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
	//Add leading zero
  if (s.length < 2) {
    s = "0" + s;
	}
  return s;
}
function getInterval() {
	var seconds = 0;
	var minutes = 0;
	var hours = 0;
	var days = 0;
	var now = new Date();
	datediff = new Date(earthHour-now);
	interval = Math.floor(datediff.valueOf()/1000);
	if (interval > 0) {
		seconds = calcage(interval,1,60);
		minutes = calcage(interval,60,60);
		hours = calcage(interval,3600,24);
		days = calcage(interval,86400,100000);
	}
	document.getElementById('ehc-d').innerHTML= days;
	document.getElementById('ehc-h').innerHTML= hours;
	document.getElementById('ehc-m').innerHTML= minutes;
	document.getElementById('ehc-s').innerHTML= seconds;

	window.setTimeout(getInterval, 1000);
}


 function initCounter() {
 
  	if (typeof(linkURL)=="undefined" || linkURL=="") {linkURL="http://earthhour.wwf.org.uk/"}
	document.write('<div id="eh09-countdown" style="width:196px;background:#000 url(http://assets.wwf.org.uk/img/original/earthhourclock.jpg) bottom no-repeat;margin-left: 14px; height:');
 document.write('172px;cursor: pointer;" onClick=location.href="'+linkURL +'">');

	document.write('<ul style="position:relative;padding:0;margin:0;list-style:none;font-size:18px;font-family:Arial, Helvetica, sans-serif;color:#FFF;text-align:center;"><li id="ehc-d" style="float:left;width:49px;padding:133px 0 0 0; background: none !important; line-height: 1em !important; "></li><li id="ehc-h" style="float:left;width:49px;padding:133px 0 0 0; background: none !important; line-height: 1em !important; "></li><li id="ehc-m" style="float:left;width:49px;padding:133px 0 0 0; background: none !important; line-height: 1em !important; "></li><li id="ehc-s" style="float:left;width:49px;padding:133px 0 0 0; background: none !important; line-height: 1em !important; "></li></ul></div>');
	
	
	getInterval();
}
initCounter();
