(function(){
		  
	var js   = window.js;
	
	var Timer = function (){
		this.pauseTime= 0;
		this.timerID  = null;
		this.delay    = 0;
		this.status   = 0; // 0 = stoped, 1 = running, 2 = poused
		this.seconds  = -1;		
	};
	
	
	Timer.prototype.start = function(callFunc){

		var startTime = (new Date()).getTime() - this.pauseTime;
		var now,min,sec,hour,time;
		
		this.startTime = startTime;
		this.callFunc  = callFunc?callFunc:null;
		
		var _this = this;
		
		var theTimer = function(){			
			now = new Date((new Date()).getTime() - startTime);						
			hour= now.getHours();
			min = now.getMinutes();
			sec = now.getSeconds();
			time= min+((sec < 10) ? ":0" : ":") + sec;
			if(callFunc)callFunc(time);
			if(_this.status == 1)
				_this.timerID = setTimeout(theTimer,1000);
		};
		
		if(this.status != 0)this.stop();
		this.status  = 1;	
		theTimer();
	};
	
	Timer.prototype.stop = function(){
		clearTimeout(this.timerID);
		this.timerID   = null;
		this.status    = 0;
		this.startTime = 0;
		this.seconds   = -1;
		this.callFunc  = null;
	};
	
	Timer.prototype.pause = function(){
		clearTimeout(this.timerID);
		this.pauseTime = (new Date()).getTime() - this.startTime;
		this.timerID = null;
		this.status  = 2;
	};
	
	Timer.prototype.resume = function(){
		this.status  = 1;
		this.start(this.callFunc);
	};	
	
	Timer.prototype.getDuration = function(){
		var t = new Date((new Date()).getTime() - this.startTime);	
		return t.getMinutes()+((t.getSeconds() < 10) ? ":0" : ":") + t.getSeconds();
	};
	
	Timer.prototype.getTimestampDuration = function(){
		var t = new Date((new Date()).getTime() - this.startTime);	
		return t.getTime();
	};
	
	Timer.prototype.getSeconds = function(){
		var t   = new Date((new Date()).getTime() - this.startTime);
		var m   = t.getMinutes();
		var mls = t.getMilliseconds();
		var s   = m > 0?m*60+t.getSeconds():t.getSeconds();
		return parseFloat(s +"."+ (mls<100?'0'+mls:mls));
	};		

	if(window.js){ 
		window.js.Timer = Timer;
	}else{
		window.js	    = {};
		window.js.Timer = Timer;
	}
	
})()
