   drawGraph(nodes, edgesForMode(mode))
 
   actOnModeButton = (the_mode, button) ->
-    removeClass('a.mode', 'btn-primary')
+    d3.select('a.mode').classed('btn-primary', true)
     mode = the_mode
-    addClass($(button), 'btn-primary')
+    d3.select(button).classed('btn-primary', true)
     drawGraph(nodes, edgesForMode(mode))
 
 
-  $('a#import').on('click', (e) ->
-    e.preventDefault()
-    actOnModeButton("import", $(this)))
-
-  $('a#all').on('click', (e) ->
-    e.preventDefault()
-    actOnModeButton("normal", $(this)))
+  d3.select('a#import').on('click', (e) ->
+    d3.event.preventDefault()
+    actOnModeButton("import", this))
+
+  d3.select('a#all').on('click', (e) ->
+    d3.event.preventDefault()
+    actOnModeButton("normal", this))

  node_url = nodes_edges[2]
  edge_url = nodes_edges[3]

  addClass($('a#all'), 'btn-primary')

  edgesForMode = (the_mode) ->
    if the_mode == "normal"

      .attr("data-label", (d) -> d.label)

    embedNodeInfo = (node) ->
      payload =
        node_url: node_url
        node: node
        url: "#{node_url}/#{node.info.id}/"
      template = templateName(edge_type, 'node')
      if template
        d3.select("div#d3_context").html('')
          .append('ul').attr('id', 'node_info')
          .html(HandlebarsTemplates[template](payload))

    embedEdgeInfo = (edge) ->
      payload =
        edge_url: edge_url
        edge: edge
      template = templateName(edge_type, 'edge')
      if template
        d3.select("div#d3_context").html('')
          .append('ul').attr('id', 'edge_info')
          .html(HandlebarsTemplates[template](payload))

    d3.selectAll("g.node").on "click", (node_data) ->
      d3.event.preventDefault()
      resetSelections()
      default_classes = "node"
      classes = "#{default_classes} selected"
      # use attr, because jquery-class doesn't work
      if window.selected_node != this
        $(window.selected_node).attr('class', default_classes)
      window.selected_node = this
      d3.select(this).attr('class', classes)
      embedNodeInfo(node_data)

    d3.selectAll("g > path").on "click", (path_data) ->
      d3.event.preventDefault()
      resetSelections()
      d3.select(this).classed('selected', true)
      embedEdgeInfo(path_data)

    d3.select('path').on('mouseenter', (e) ->
      d3.selectAll('g.node').classed('highlight', false)
      path_data = d3.select(this).data()[0]
      source_index = path_data.source.index
      target_index = path_data.target.index
      d3.select(node[0][source_index]).classed('highlight', true)
      d3.select(node[0][target_index]).classed('highlight', true)
    )
    d3.select('path').on('mouseleave', (e) -> d3.selectAll('g.node').classed('highlight', false))

    node.append("circle").
      attr("r", (d) -> if d.is_center then 10 else 7)
