/***********************************************************************************************************
 * su.bot.checkers.javascript.Clock
 * Location: http://www.bot.su/library/su/bot/checkers/javascript/Clock.js
 * Index Version Location: http://www.bot.su/library/su/bot/checkers/javascript/clock/index.html
 * © Bot.Su (http://www.bot.su/)
***********************************************************************************************************/

if (typeof su == "undefined") {su = {};};
if (typeof su.bot == "undefined") {su.bot = {};};
if (typeof su.bot.checkers == "undefined") {su.bot.checkers = {};};
if (typeof su.bot.checkers.javascript == "undefined") {su.bot.checkers.javascript = {};};

if (typeof su.bot.checkers.javascript.Clock == "undefined") {
 su.bot.checkers.javascript.Clock = function() {}; 
 su.bot.checkers.javascript.Clock.prototype = new com.oclib.javascript.lang.Root();

 su.bot.checkers.javascript.Clock.prototype.className = "Clock"; 
 su.bot.checkers.javascript.Clock.prototype.classNamespace = "su.bot.checkers.javascript.Clock"; 
 su.bot.checkers.javascript.Clock.prototype.classCreated = "20070403"; 
 su.bot.checkers.javascript.Clock.prototype.classCreator = "http://www.bot.su/"; 
 su.bot.checkers.javascript.Clock.prototype.classLocation = "http://www.bot.su/library/su/bot/checkers/javascript/Clock.js"; 
 su.bot.checkers.javascript.Clock.prototype.classIndexLocation = "http://www.bot.su/library/su/bot/checkers/javascript/clock/index.html"; 
 su.bot.checkers.javascript.Clock.prototype.classVersion = "20070528"; 
 su.bot.checkers.javascript.Clock.prototype.classVersionLocation = "http://www.bot.su/library/su/bot/checkers/javascript/clock/builds/20070528/Clock.js"; 
 su.bot.checkers.javascript.Clock.prototype.classVersionIndexLocation = "http://www.bot.su/library/su/bot/checkers/javascript/clock/index.html"; 
 
 su.bot.checkers.javascript.Clock.prototype.currentName = "empty"; /*"max", "min", "empty"*/
  su.bot.checkers.javascript.Clock.prototype.getCurrentName = function () {return this.currentName;};
  su.bot.checkers.javascript.Clock.prototype.setCurrentName = function (currentName) {this.currentName = currentName;};  
 su.bot.checkers.javascript.Clock.prototype.environment;
  su.bot.checkers.javascript.Clock.prototype.getEnvironment = function () {return this.environment;};
  su.bot.checkers.javascript.Clock.prototype.setEnvironment = function (environment) {this.environment = environment;}; 
 su.bot.checkers.javascript.Clock.prototype.gameTime = 0;
  su.bot.checkers.javascript.Clock.prototype.getGameTime = function () {return this.gameTime;};
  su.bot.checkers.javascript.Clock.prototype.setGameTime = function (gameTime) {this.gameTime = gameTime;}; 
 su.bot.checkers.javascript.Clock.prototype.maxCurrentTime = 0;
  su.bot.checkers.javascript.Clock.prototype.getMaxCurrentTime = function () {return this.maxCurrentTime;};
  su.bot.checkers.javascript.Clock.prototype.setMaxCurrentTime = function (maxCurrentTime) {this.maxCurrentTime = maxCurrentTime;}; 
 su.bot.checkers.javascript.Clock.prototype.maxFullTime = 0;
  su.bot.checkers.javascript.Clock.prototype.getMaxFullTime = function () {return this.maxFullTime;};
  su.bot.checkers.javascript.Clock.prototype.setMaxFullTime = function (maxFullTime) {this.maxFullTime = maxFullTime;}; 
 su.bot.checkers.javascript.Clock.prototype.maxLastFullTime = 0;
  su.bot.checkers.javascript.Clock.prototype.getMaxLastFullTime = function () {return this.maxLastFullTime;};
  su.bot.checkers.javascript.Clock.prototype.setMaxLastFullTime = function (maxLastFullTime) {this.maxLastFullTime = maxLastFullTime;}; 
 su.bot.checkers.javascript.Clock.prototype.maxStartTime = null;
  su.bot.checkers.javascript.Clock.prototype.getMaxStartTime = function () {return this.maxStartTime;};
  su.bot.checkers.javascript.Clock.prototype.setMaxStartTime = function (maxStartTime) {this.maxStartTime = maxStartTime;}; 
 su.bot.checkers.javascript.Clock.prototype.minCurrentTime = 0;
  su.bot.checkers.javascript.Clock.prototype.getMinCurrentTime = function () {return this.minCurrentTime;};
  su.bot.checkers.javascript.Clock.prototype.setMinCurrentTime = function (minCurrentTime) {this.minCurrentTime = minCurrentTime;}; 
 su.bot.checkers.javascript.Clock.prototype.minFullTime = 0 ;
  su.bot.checkers.javascript.Clock.prototype.getMinFullTime = function () {return this.minFullTime;};
  su.bot.checkers.javascript.Clock.prototype.setMinFullTime = function (minFullTime) {this.minFullTime = minFullTime;};
 su.bot.checkers.javascript.Clock.prototype.minLastFullTime = 0 ;
  su.bot.checkers.javascript.Clock.prototype.getMinLastFullTime = function () {return this.minLastFullTime;};
  su.bot.checkers.javascript.Clock.prototype.setMinLastFullTime = function (minLastFullTime) {this.minLastFullTime = minLastFullTime;};
 su.bot.checkers.javascript.Clock.prototype.minStartTime = null;
  su.bot.checkers.javascript.Clock.prototype.getMinStartTime = function () {return this.minStartTime;};
  su.bot.checkers.javascript.Clock.prototype.setMinStartTime = function (minStartTime) {this.minStartTime = minStartTime;};   
 su.bot.checkers.javascript.Clock.prototype.updated = false;
  su.bot.checkers.javascript.Clock.prototype.getUpdated = function () {return this.updated;};
  su.bot.checkers.javascript.Clock.prototype.setUpdated = function (updated) {this.updated = updated;};  
  
 su.bot.checkers.javascript.Clock.prototype.change = function(toName) {
  //if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.Clock.change is runing for toName="+toName);};
  this.setUpdated(false);
  this.setCurrentName(toName);
  this.setMaxCurrentTime(0);
  this.setMaxLastFullTime(this.getMaxFullTime());
  this.setMaxStartTime(null);
  this.setMinCurrentTime(0);
  this.setMinLastFullTime(this.getMinFullTime());
  this.setMinStartTime(null);
  if(toName == "max") {
   this.setMaxStartTime(new Date());
  } else if(toName == "min") {
   this.setMinStartTime(new Date());
  };
  this.setUpdated(true);
 };
  
 su.bot.checkers.javascript.Clock.prototype.pause = function() {
  if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.Clock.pause is runing...");};
  this.setUpdated(false);
 };
  
 su.bot.checkers.javascript.Clock.prototype.run = function() {
  //if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.Clock.run is runing...");};
  this.setGameTime(0);
  this.setMaxCurrentTime(0);
  this.setMaxFullTime(0);
  this.setMaxLastFullTime(0);
  this.setMaxStartTime(null);
  this.setMinCurrentTime(0);
  this.setMinFullTime(0);
  this.setMinLastFullTime(0);
  this.setMinStartTime(null);
  this.update();
 };
  
 su.bot.checkers.javascript.Clock.prototype.end = function() {
  if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.Clock.end is runing...");};
  this.pause();
 };
  
 su.bot.checkers.javascript.Clock.prototype.update = function() {
  //if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.Clock.update is runing...");};
  if(this.updated) {
   var nowTime = (new Date()).getTime();
   if(this.currentName == "max") {
    var maxTime = nowTime - this.getMaxStartTime();
    this.maxCurrentTime = maxTime;
    this.maxFullTime = this.maxLastFullTime + maxTime;
   } else if(this.getCurrentName() == "min")  {
    var minTime = nowTime - this.getMinStartTime();
    this.minCurrentTime = minTime;
    this.minFullTime = this.minLastFullTime + minTime;
   };
   this.gameTime = this.maxFullTime+this.minFullTime;
  };
  var the = this; setTimeout(function(){the.update();}, 1000);
 };
};
