/** constructor 
@param duration integer seconds
@param <optional> function to run while waiting.
*/
function Pause(duration, callback){
    this.duration= duration;
    this.callback = null; // function to call while waiting.
    this.runner = 0;
    
    if (arguments.length == 2) {
      this.callback = callback;
    }
    this.pause(this.duration);
} // Pause class

/** pause method 
@param duration: integer in seconds
*/
Pause.prototype.pause = function(duration){
    if ( (duration == null) || (duration < 0)) {return;}
    var later = (new Date()).getTime() + duration;
    while(true){
      if ((new Date()).getTime() > later) {
         break;
      }
      this.runner++;
      if (this.callback != null) {
         this.callback(this.runner);
      }
    } // while
} // pause method