//*********************************//
//* TimeMachine functions         *//
//*********************************//

function TimeMachine(id,date) {
  bindMethods(this);
  this.id_source = id;
  this.date = date;
  this.timer = null;
}

TimeMachine.prototype.invoqueJSONdataRequest = function() {
  this.req = getXMLHttpRequest();
  if (this.req.overrideMimeType) { this.req.overrideMimeType("text/xml"); }
  this.req.open('GET', '/action/get_stories.php?id='+this.id_source+'&date='+this.date, true);
  d = sendXMLHttpRequest(this.req).addCallback(this.renderSource);
}

TimeMachine.prototype.renderSource = function(r) {
	js=r.responseText;
	eval(js);
}

TimeMachine.prototype.cancelTimer = function () {
        if (this.timer) this.timer.cancel();
        this.timer = null;
}

TimeMachine.prototype.restartTimer = function () {
        this.cancelTimer();
        if(this.time_refresh != null) this.timer = callLater(this.time_refresh, this.invoqueJSONdataRequest);
}

function loadSourceStories(id,date)
{
	e=gebi('canvas'+id);
	e.innerHTML='<img src=\"/img/loading.gif\">';
        e=gebi('g'+id);
        e.innerHTML='<img src=\"/img/loading.gif\">';

	backintime = new TimeMachine(id,date);
	backintime.invoqueJSONdataRequest();
}
