

(function($,$global) {


var $d = $(), timeout, threshold, time, timeMod1000, nextSecond;

function tick() {
	time = (new Date()).getTime();
	timeMod1000 = time % 1000;
	nextSecond = time + (1000 - timeMod1000);
	return time;
}

function schedule() {
	timeout = setTimeout(action,
		(timeMod1000 < 750) ? 200 :
		(timeMod1000 < 925) ? 100 :
		Math.max(1, 985 - timeMod1000)
	);
}

function action() {
	if( tick() >= threshold ) {
		threshold = nextSecond;
		$d.trigger('eachSecond',[time]);
	}
	schedule();
}

threshold = tick() + 1;
schedule();


})(jQuery,this);
