
Timer = function(object){
	this.timestamp =  ('Timestamp'	  in object)?object['Timestamp']    :null;
	this.dest      =  ('Destination'  in object)?object['Destination']  :null;
	this.timestamp*=1000;
	this.theDate = new Date( this.timestamp );
}


Timer.prototype.countDown = function(){
	var self = this;
	    self.start(-1000);
}

Timer.prototype.getCurrentTime = function(){
	var self = this;
		
	    self.start(1000);
}

Timer.prototype.setCurrantTime = function(time){
	var self = this;
		self.theDate = new Date(time);
}

Timer.prototype.start = function(count){
 var self = this;
    with(self){ 
		
		with(theDate){
		
			var h =   (getHours()-1).toString();
			var m = getMinutes().toString();
			var s = getSeconds().toString();
				
			var text = "";
				
			    if((getHours()-1) != 0)text += h+"godz. ";
				if(getMinutes() != 0||(getHours()-1) != 0)text += ((m.length==1)?"&nbsp;"+m:m)+"min. "; 
			    if(getSeconds() != 0||getMinutes()!=0||(getHours()-1)!= 0)text += ((s.length==1)?"0"+s:s)+"sek."; 
				if(text == "" || timestamp <=0)	text = "  ";

				dest.innerHTML = text;
		    } 
			
			timestamp += count;
			setCurrantTime(timestamp);
			
		    if(text != " zakończono ") setTimeout(function(){start(count)},1000);
	}
}

Timer.prototype.start2 = function(){
 var self = this;
    with(self){ 

	
			/*	
			var text = "";
				
		

				dest.innerHTML = text;
		    } */
			
		set();
		setInterval(function(){
			set();
		},1000);
		}
	
}

Timer.prototype.set = function(){
	var self= this;
	with(self){
		with(theDate){
			var h =   (getHours()).toString();
			var m = getMinutes().toString();
			var s = getSeconds().toString();
			
			var text = "";
			
				if((getHours()) != 0) text += h+":";
				if(getMinutes() != 0||(getHours()) != 0)text += ((m.length==1)?"0"+m:m); 
			  //  if(getSeconds() != 0||getMinutes()!=0||(getHours())!= 0)text += ((s.length==1)?"0"+s:s); 
				if(text == "" || timestamp <=0)	text = "  ";
	
				dest.innerHTML = text;	
			} 
		timestamp+=1000;
		theDate = new Date(timestamp);
	}
}

Timer.init = function(timestamp,id){
	var elem = (typeof id =='string')?Element.getByID(id):id;	
		return date = new Timer({Timestamp:timestamp, Destination: elem});
}



