
red.prototype.timer = {
	
	timer : null,
	
	then : null,
	
	now : null,
	
	pause : null,
		
	diplayid : null,
	
	starttime : '',
	
	clientserver_diff : 0,
		
	start : function(displayid,serverzeit){
		red.prototype.timer.diplayid = displayid;
		document.getElementById(displayid).innerHTML = '00:00:00';
		red.prototype.timer.then = new Date();
		if(serverzeit != null){
			red.prototype.timer.clientserver_diff = red.prototype.timer.then.getTime()-serverzeit;
		}
		red.prototype.timer.then.setTime(red.prototype.timer.then.getTime()+red.prototype.timer.clientserver_diff)
		if(red.prototype.timer.starttime != ''){
			//millisekunden seit 1970
			red.prototype.timer.then.setTime(red.prototype.timer.starttime+red.prototype.timer.clientserver_diff);
		}
		red.prototype.timer.startnow();
		
	},

	startnow : function(){
		red.prototype.timer.timer = window.setTimeout("red.prototype.timer.go()", 1000);
	},
	
	go : function(){
		red.prototype.timer.now = new Date();
		red.prototype.timer.now.setTime(new Date() - red.prototype.timer.then); 
		
		var min = red.prototype.timer.now.getMinutes(); 
		var sec = red.prototype.timer.now.getSeconds(); 
		var hour = Math.floor( red.prototype.timer.now / 3600000 );
		
		min = ( min < 10 ) ? "0" + min : min;
		sec = ( sec < 10 ) ? "0" + sec : sec;	
		hour = ( hour < 10 ) ? "0" + hour : hour;	
		
		document.getElementById(red.prototype.timer.diplayid).innerHTML = hour+':'+min+':'+sec;
		red.prototype.timer.startnow();
	},
	
	stop : function(){
		red.prototype.timer.pause = new Date();
		window.clearTimeout(red.prototype.timer.timer);
	},
		
	newstart : function(){
		window.clearTimeout(red.prototype.timer.timer);
		red.prototype.timer.start();
	}
}	
	
	
	
/*
var timer;
var then;
var now;
var pause;
var min=0;
var hour=0;
function startwatch(){
	then=new Date();
	startnow();
}
function startnow(){
	timer=setTimeout("go()", 1000);
}
function go(){
	now=new Date();
	now.setTime(new Date() - then); 
	min = now.getMinutes(); 
	sec = now.getSeconds(); 
	hour = Math.floor( now / 3600000 );
	
	min = ( min < 10 ) ? "0" + min : min;
	sec = ( sec < 10 ) ? "0" + sec : sec;	
	hour = ( hour < 10 ) ? "0" + hour : hour;	
	
	document.getElementById("infotime").innerHTML = hour+':'+min+':'+sec;
	startnow();
}
function stop(){
	pause=new Date();
	clearTimeout(timer);
}
function cont(){
	pauseoff=new Date();
	ss=pauseoff.getSeconds()-pause.getSeconds()+then.getSeconds()+1;
	mm=pauseoff.getMinutes()-pause.getMinutes()+then.getMinutes();
	hh=pauseoff.getHours()-pause.getHours()+then.getHours();
	dd=pauseoff.getDate();
	mo=pauseoff.getMonth();
	yy=pauseoff.getYear();
	if (ss>60){
	ss-=60;
	mm++;
	} else if (ss<0){
	ss+=60;
	mm--;
	}
	if (mm>60){
	mm-=60;
	hh++;
	} else if (mm<0){
	mm+=60;
	hh--;
	}
	then=new Date(yy,mo,dd,hh,mm,ss);
	startnow();
}
function newstart(){
	clearTimeout(timer);
	document.getElementById("infotime").innerHTML = '00:00:00';
	min=0;
	hour=0;
	startwatch();
}
function conton(){
	now=new Date();
	min=now.getMinutes()-then.getMinutes();
	if(now.getSeconds()<then.getSeconds())
	min--;
	hour=now.getHours()-then.getHours();
	if(now.getMinutes()<then.getMinutes())
	hour--;
	startnow();
}
*/	
	



