/***********************************************************************************************************
 * su.bot.checkers.javascript.VisualClock
 * Location: http://www.bot.su/library/su/bot/checkers/javascript/VisualClock.js
 * Index Version Location: http://www.bot.su/library/su/bot/checkers/javascript/visualclock/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.VisualClock == "undefined") {
 su.bot.checkers.javascript.VisualClock = function() {}; 
 su.bot.checkers.javascript.VisualClock.prototype = new com.oclib.javascript.lang.Root();

 su.bot.checkers.javascript.VisualClock.prototype.className = "VisualClock"; 
 su.bot.checkers.javascript.VisualClock.prototype.classNamespace = "su.bot.checkers.javascript.VisualClock"; 
 su.bot.checkers.javascript.VisualClock.prototype.classCreated = "20070403"; 
 su.bot.checkers.javascript.VisualClock.prototype.classCreator = "http://www.bot.su/"; 
 su.bot.checkers.javascript.VisualClock.prototype.classLocation = "http://www.bot.su/library/su/bot/checkers/javascript/VisualClock.js"; 
 su.bot.checkers.javascript.VisualClock.prototype.classIndexLocation = "http://www.bot.su/library/su/bot/checkers/javascript/visualclock/index.html"; 
 su.bot.checkers.javascript.VisualClock.prototype.classVersion = "20070528"; 
 su.bot.checkers.javascript.VisualClock.prototype.classVersionLocation = "http://www.bot.su/library/su/bot/checkers/javascript/visualclock/builds/20070528/VisualClock.js"; 
 su.bot.checkers.javascript.VisualClock.prototype.classVersionIndexLocation = "http://www.bot.su/library/su/bot/checkers/javascript/visualclock/index.html"; 
 
 su.bot.checkers.javascript.VisualClock.prototype.environment;
  su.bot.checkers.javascript.VisualClock.prototype.getEnvironment = function () {return this.environment;};
  su.bot.checkers.javascript.VisualClock.prototype.setEnvironment = function (environment) {this.environment = environment;}; 

 su.bot.checkers.javascript.VisualClock.prototype.changeTextContent = function(eId, c) {
  //if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.VisualClock is running...");}; 
  var e = document.getElementById(eId);
  while(e.hasChildNodes() && e.firstChild) {e.removeChild(e.firstChild);};
  e.appendChild(document.createTextNode(c));
 }; 
  
 su.bot.checkers.javascript.VisualClock.prototype.run = function() {
  if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.VisualClock.run is runing...");};
  this.clock = environment.getClock();
  this.dom = environment.getDom();
  this.properties = environment.getProperties();
  this.currentTimeId = this.properties.getCurrentTimeId();
  this.gameTimeId = this.properties.getGameTimeId();
  this.maxCurrentTimeId = this.properties.getMaxCurrentTimeId();
  this.maxFullTimeId = this.properties.getMaxFullTimeId();
  this.minCurrentTimeId = this.properties.getMinCurrentTimeId();
  this.minFullTimeId = this.properties.getMinFullTimeId();
  this.update();
 };
  
 su.bot.checkers.javascript.VisualClock.prototype.msToString = function(ms) {
  //if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.VisualClock.secToString is runing...");};
  var sec = Math.round(ms/1000);
  var s = sec%60;
  var ss = ((s < 10) ? "0" : "") + s;
  var m = (sec - s)/60%60;
  var mm = ((m < 10) ? "0" : "") + m;
  var h = (sec - s - m*60)/360%60;
  var hh = ((h < 10) ? "0" : "") + h;
  return "" + hh + " : "+ mm + " : "+ ss + "";
 };
  
 su.bot.checkers.javascript.VisualClock.prototype.update = function() {
  // if(this.mustTrace()) {this.getLog().println("su.bot.checkers.javascript.VisualClock.update is runing...");};
  this.changeTextContent(this.currentTimeId, (new Date()).toLocaleString());
  this.changeTextContent(this.gameTimeId, this.msToString(this.clock.getGameTime()));
  this.changeTextContent(this.maxCurrentTimeId, this.msToString(this.clock.getMaxCurrentTime()));
  this.changeTextContent(this.maxFullTimeId, this.msToString(this.clock.getMaxFullTime()));
  this.changeTextContent(this.minCurrentTimeId, this.msToString(this.clock.getMinCurrentTime()));
  this.changeTextContent(this.minFullTimeId, this.msToString(this.clock.getMinFullTime()));
  var the = this; setTimeout(function(){the.update();}, 1015);
 };
};
