var OTO = {

   seconds : 30,

   layerObject : null,
   timer : null,

   start : function(layer, secondsLeft) {
      if (secondsLeft != undefined) {
         OTO.seconds = parseInt(secondsLeft);
      }
      OTO.layerObject = document.getElementById(layer);

      OTO.timer = setInterval("OTO.go()", 1000);
   },

   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 + " days"; }
      if (hours > 0) { result[result.length] = hours + " hours"; }
      if (minutes > 0) { result[result.length] = minutes + " minutes"; }
      if (seconds > 0) { result[result.length] = seconds + " seconds"; }

      return result.join(", ");
   },

   go : function() {
      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

};