var OTO = {

   seconds : 60,

   layerObject : null,
   timer : null,

   start : function(layer, secondsLeft) {
      if (secondsLeft != undefined) {
         OTO.seconds = parseInt(secondsLeft);
      }
      //alert(secondsLeft+"|"+layer)
      OTO.layerObject = document.getElementById(layer);
	  //alert(OTO.layerObject);
      OTO.timer = setInterval("OTO.go()", 2000);
   },

   secondsToString : function(totalSeconds) {
      totalSeconds = parseInt(totalSeconds);

      var days = Math.floor(totalSeconds / (60*60*24));
      var hours = Math.floor(totalSeconds / (60*60));
      var minutes = Math.floor(totalSeconds / 60);
      var seconds = parseInt(totalSeconds % 60);

      var result = new Array();

      if (days > 0) { result[result.length] = days + " d "; }
      if (hours > 0) { result[result.length] = hours + ":"; }
      if (minutes >= 0) { result[result.length] = minutes + ":"; }
      if (seconds >= 0) { 
      					secondsstr="0"+seconds;
      					secondsstr=secondsstr.substr(secondsstr.length-2,2);
      					result[result.length] = secondsstr + " ";
      					}
      return result.join("");
   },

   go : function() {
      OTO.seconds--;
      //alert(OTO.secondsToString(OTO.seconds));
      OTO.layerObject.innerHTML = OTO.secondsToString(OTO.seconds) + "";
      // Subtract 1 from seconds

      if (OTO.seconds <= 0) {
         clearInterval(OTO.timer);
         if (OTO.onEnd != null) {
            OTO.onEnd();
         }
      }
   },

   // bind this to a JavaScript function on your own
   onEnd : null

};
