   tagName: 'li'
   initialize: ->
     @listenTo @model, 'change', @render
-    @listenTo @model, 'assigned', @assign
-    @listenTo @model, 'completed', @completed
-
-  assign: (worker)->
-    left = worker.get('left') - @$el.offset().left
-    top  = worker.get('top')  - @$el.offset().top
-    @$el.animate {translateX: "#{left}px", translateY: "#{top}px"},
-      duration: 500
-      complete: =>
-        @$el.remove()
-          .animate {translateX: "0px", translateY: "0px"}, duration: 0, complete: =>
-            @$el.appendTo $('#workers > li').eq(worker.id).find 'ul'
-
-
-  completed: ->
-    left = $('#finished').offset().left - @$el.offset().left
-    top  = $('#finished').offset().top  - @$el.offset().top
-    console.log left, top
-    @$el.animate {translateX: "#{left}px", translateY: "#{top}px"},
-      duration: 500
-      complete: =>
-        @$el.remove()
-          .animate {translateX: "0px", translateY: "0px"}, duration: 0, complete: =>
-            @$el.prependTo $ '#finished'
 
   render: ->
-    @$el.addClass( @model.get 'status' ).html "<p>#{@model.title()}</p>"
+    @$el.removeAttr('class').addClass( @model.get 'status' ).html "<p>#{@model.title()}</p>"
     _(@model.get('dots')).each (dot)=> @$el.append $('<span>').addClass dot
     this
 
 class View.Worker extends Backbone.View
   tagName: 'li'
 
+  jobList: -> @$ 'ul'
+
   render: ->
     @$el.html "<p>#{@model.id}</p><ul></ul>"
     this
 
+class View.Transition extends Backbone.View
+  initialize: (options)->
+    @target = options.target
+
+  render: ->
+    left = @target.offset().left - @$el.offset().left
+    top  = @target.offset().top  - @$el.offset().top
+    @$el.animate {translateX: "#{left}px", translateY: "#{top}px"},
+      duration: 500
+      complete: =>
+        @$el.remove()
+          .animate {translateX: "0px", translateY: "0px"}, duration: 0, complete: =>
+            @$el.prependTo @target
+
 class View.Flatware extends Backbone.View
   initialize: ->
-    @listenTo @model.jobs, 'add', (job)->
-      new View.Job(model: job).render().$el.appendTo '#waiting'
+    @finished = @$ '#finished'
+    @jobViews = {}
+    @listenTo @model.jobs, 'add', @addJob
+    @listenTo @model.workers, 'add', @addWorker
 
-    @listenTo @model.workers, 'add', (job)->
-      workerView = new View.Worker(model: job).render()
-      workerView.$el.appendTo '#workers'
-      workerView.model.set workerView.$el.offset()
+  addJob: (job)=>
+    jobView = new View.Job(model: job)
+    @jobViews[job.id] = jobView
+    jobView.render().$el.appendTo '#waiting'
+    @listenTo job, 'completed', =>
+      new View.Transition(el: jobView.el, target: @finished).render()
+
+  addWorker: (worker)=>
+    workerView = new View.Worker(model: worker).render()
+    workerView.$el.appendTo '#workers'
+    @listenTo worker, 'assigned', (_, job)=>
+      new View.Transition(el: @jobViews[job.id].el, target: workerView.jobList()).render()

  source.onerror = (e)-> console.log e.type
  source.onopen  = (e)-> console.log e.type

  new View.Flatware model: flatware

class Flatware extends Backbone.Model
  initialize: ->


  initialize: ->
    @on 'change', -> @get('job')?.set @pick 'status', 'dots'
    @on 'change:job', (worker, job)->
      if completed = worker.previousAttributes().job
        @trigger 'completed', worker, completed
      @trigger 'assigned', worker, job if job
      @set dots: []

class Workers extends Backbone.Collection
  model: Worker
