var runner =
{
  stopFlag: false,
  // przesanianie funkcji
  onmessage: function (msg)
  {
    if (msg.state)
    {
      var state = msg.state;
      $('#status').html("czas: " + state.time);
    }
    if (msg.set)
    {
      this.state = msg.set;
    }
    return this.state;
  },
  postMessage: function (message)
  {
    this.onmessage(message);
  },
stop: function ()
  {
    this.stopFlag = true;
  },
  error: function (error)
  {
    this.stopFlag = true;
  },
  setup: function (run, state)
  {
    this.run = run;
    this.state = state;
    this.execute();
  },
  execute: function ()
  {
    var that = this;
    setTimeout(function runIterator()
    {
      that.state = that.run.apply(that, [that.state]);
      if (that.stopFlag)
      {
        that.postMessage(that.state);
      }
      else
      {
        that.execute();
      }
    }, 250);
  }
};