var Cookie = {

   set : function(name, value, days) {
      // Default to a 1 year cookie
      if (days == undefined) { days = 365; }

      // Format date string
      var date = new Date();
      date.setTime(date.getTime() + (days * 86400000));

      // Set cookie name, value, and expiration date
      document.cookie = name + "=" + value + "; expires=" + date.toGMTString() + "; path=/";
   },

   get : function(name) {
      // Find the cookie's value in the document cookie string
      var results = document.cookie.match(
         new RegExp("(?:^|; )" + name + "=" + "(.*?)(?:$|;)")
      );

      // Return the value if a match was found, undefined otherwise
      if (results && results.length > 1) return results[1];
      return undefined;
   },

   clear : function(name) {
      // Erase a cookie
      setCookie(name, "", -1);
   }

};

var OTO = {

   seconds : 30,

   layerObject : null,
   timer : null,

   start : function(layer) {
      OTO.layerObject = document.getElementById(layer);

      var value = parseInt(OTO.layerObject.innerHTML);
      if (!isNaN(value) && value > 0) {
         OTO.seconds = value;
      }

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

   go : function() {
      OTO.seconds--;
      OTO.layerObject.innerHTML = 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

};