// DHTML Clock Object

// a widget that writes the date and current time (with updating seconds) to 2 individual layers

// 19990330



// Copyright (C) 1999 Dan Steinman

// Distributed under the terms of the GNU Library General Public License

// Available at http://www.dansteinman.com/dynduo/



function Clock(dateX,dateY,timeX,timeY) {

	this.name = "Clock"+(Clock.count++)

	this.obj = this.name + "Object"

	eval(this.obj + "=this")

	this.dateX = dateX

	this.dateY = dateY

	this.timeX = timeX

	this.timeY = timeY

	this.showSeconds = true

	this.twelveHour = true

	this.showTime = true

	this.activate = ClockActivate

	this.getTime = ClockGetTime

	this.build = ClockBuild

	this.tick = ClockTick

	this.calc_correction = ClockCalcCorrection
   this.correction = 0;
   this.correction_m = 0;
   this.correction_s = 0;

}

function ClockBuild() {

	this.getTime()
/*
	this.css = css(this.name+'Date',this.dateX,this.dateY)+

	css(this.name+'Time',this.timeX,this.timeY)+

	'.'+this.name+'DateStyle {'+this.dateStyle+'}\n'+

	'.'+this.name+'TimeStyle {'+this.timeStyle+'}\n'
*/

	this.timeDiv = '<div id="'+this.name+'Time"><div class="CLOCK">'+this.time+'</div></div>'
//	this.timeDiv = '<div id="'+this.name+'Time"><div class="CLOCK"></div></div>'

	this.div = ''

	if (this.showTime) this.div += this.timeDiv

}

function ClockActivate() {

	if (this.showTime) {

		this.timelyr = new DynLayer(this.name+"Time")

		this.timelyr.write = DynLayerWrite

	}

   this.calc_correction()
	this.tick()

}

function ClockGetTime() {
	var now = new Date()
	this.newmin = now.getMinutes()
	var hour = now.getHours()
   var sec = now.getSeconds()
   sec += this.correction_s;
   while (sec>59) {
      sec -= 60;
      this.newmin++;
   }
   while (sec<0) {
      sec += 60;
      this.newmin--;
   }
   this.newmin += this.correction_m;
   while (this.newmin>59) {
      this.newmin -= 60;
      hour++;
   }
   while (this.newmin<0) {
      this.newmin += 60;
      hour--;
   }
   while (hour>23) {
      hour -= 24;
      // zmienic date (odjac dzien)
   }
   while (hour<0) {
      hour = 24-hour;
      // zmienic date (dodac dzien)
   }

	if (this.newmin<10) this.newmin = "0"+this.newmin

	if (hour<10) hour = "&nbsp;"+hour
	this.time = hour+"&nbsp;:&nbsp;"+this.newmin
	if (this.showSeconds) {
		if (sec<10) sec = "0"+sec
		this.time += "&nbsp;:&nbsp;"+sec
	}
}

function ClockTick() {

	this.getTime()

	if (this.oldmin!=this.newmin || this.showSeconds) {

		if (this.showTime) this.timelyr.write('<div class="CLOCK">'+this.time+'</div>')

		this.oldmin = this.newmin

	}

	setTimeout(this.obj+".tick()",1000)

}

Clock.count = 0

