// JavaScript Document

var counterWrap = document.getElementById('counterWrap');
var htmlLink = document.getElementById('DoNotDeleteThisLink');

if(htmlLink != "http://www.explain2012.com/" || htmlLink.innerHTML != "End of The World")
{
	counterWrap.style.display = "none";
}

htmlLink.innerHTML = "End of The World?<br />www.Explain2012.com";

counterWrap.style.textAlign = "center";
counterWrap.style.width = "180px";
counterWrap.style.marginBottom = "45px";

htmlLink.style.position = "relative";
htmlLink.style.top = "140px";

htmlLink.style.textDecoration = "none";
htmlLink.style.fontSize = "10px";
htmlLink.style.color = "#bbb";
htmlLink.style.fontFamily = "Helvetica, Arial, sans-serif";


TargetDate = "12/21/2012 12:00 AM";
BackColor = "#09213b";
ForeColor = "#fff";
CountActive = true;
CountStepper = -1;
LeadingZero = true;

DisplayFormat = "<div style='color: #666; font-size: 12px; height: 70px; width: 180px; font-family:Courier New, Courier, monospace;	line-height: 18px;	padding-top: 30px; font-weight:bold; background-image: url(http://www.explain2012.com/widget/assets/bg.png); background-repeat: no-repeat; background-position: top;'><div style='float:left; margin: 0px 8px 0px 12px; text-align:center;'><span style='color:#472b00; font-size: 16px;'>%%D%%</span><br />Days</div><div style='float:left; margin-right: 8px; text-align:center;'><span style='color:#472b00; font-size: 16px;'>%%H%%</span><br />Hours</div><div style='float:left; margin-right: 8px; text-align:center;'><span style='color:#472b00; font-size: 16px;'>%%M%%</span><br />Mins</div><div style='float:left; text-align: center;'><span style='color:#472b00; font-size: 16px;'>%%S%%</span><br />Secs</div></div>";

function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack(secs) {
  if (secs < 0) {
    document.getElementById("cntdwn").innerHTML = FinishMessage;
    return;
  }
  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  document.getElementById("cntdwn").innerHTML = DisplayStr;
  if (CountActive)
    setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
 document.write("<span id='cntdwn'></span>");
}

CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
  CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
putspan(BackColor, ForeColor);
var dthen = new Date(TargetDate);
var dnow = new Date();
if(CountStepper>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);