function showcounter() {
	AfictionGames.GetCounter(showcounter_callback);
}

function showcounter_callback(res) {
	if(res != null ) {
	    $("counterspan").innerText =res.value;
	}
}

var ServerTime = Class.create();

Object.extend(ServerTime.prototype, {

	callback: function(res) {
		if(res != null && res.value != null) {
			this.currentTime = res.value;
			if(Function.isFunction(this.ondata)) {
				setTimeout(this.ondata.bind(this),1);
			}
		}
		setTimeout(this.run.bind(this), this.tickertime);
	},
	start: function() {
		if(this.isRunning) return;
		this.isRunning = true;
		this.run();
	},
	run: function() {
		if(this.isRunning) {
			AfictionGames.GetCounter(this.callback.bind(this), null, AjaxPro.noOperation);
		}
	},
	stop: function() {
		this.isRunning = false;
	},
	initialize: function(id,tickertime) {
		this.id = id;
		this.isRunning = false;
		this.ondata = null;
		this.tickertime=tickertime;
	}

});

var countertime = new ServerTime(1,1000);
countertime.ondata = function() {
	showcounter();
}
countertime.start();
