 
 Group.on 'fetch', (e, groups) ->
   currentProject.groups = groups
+  
+ms.addEvent 'marking-surface:element:start', 'rect', (e) ->
+  current_tool?.el.classList.remove 'selected'
+  current_tool = (tool for tool in ms.tools when tool.outline?.el is e.target)[0]
+  current_tool?.el.classList.add 'selected'
+  
   
 ms.on 'marking-surface:add-tool', (tool) ->
   {label} = decisionTree.currentTask.getChoice() ? ''

    decisionTree.currentTask.confirmButton.innerHTML = label if label?
  
  current_tool?.mark.details = value if key is 'details'
  current_tool?.mark.parts = value if key is 'parts'

classify_page.on classify_page.LOAD_SUBJECT, (e, subject)->
  ms.rescale 0, 0, subjectViewer.maxWidth, subjectViewer.maxHeight

  @rescale() if @scaleX is 0

LAST_TASK = true
INITIAL_STEPS = 3 # number of initial steps before annotating rectangles
ANNOTATION_STEPS = 1 # number of annotation steps per rectangle
MARGIN = 25 # margin on cropped images

current_tool = null
