 else
   graphs_uri += "/graphs" if graphs_uri.search(/\/graphs/) == -1
 
-$('div#graph_depth_setting ul li a').on 'click', (e) ->
-  e.preventDefault()
-  depth = parseInt($(this).html())
-
-  $('div#graph_depth_setting > a').html(depth)
-    .append($('<span />', class: 'caret'))
+d3.select('div#graph_depth_setting ul li a').on 'click', (e) ->
+  d3.event.preventDefault()
+  depth = parseInt(d3.select(this).html())
+
+  d3.select('div#graph_depth_setting > a').html(depth)
+    .append('span').attr('class', 'caret')
 
   $.get("#{graphs_uri}?depth=#{depth}", (data) ->
       displayGraph(data)

    zoom_listener = d3.behavior.zoom().
      scaleExtent([0.1, 3]).on("zoom", zoom)

    $("div#d3_graph").html("")
    svg = d3.select("div#d3_graph")
      .append('svg')
      .attr('width', width)

  drawGraph(nodes, edgesForMode(mode))

  actOnModeButton = (the_mode, button) ->
    d3.select('a.mode').classed('btn-primary', true)
    mode = the_mode
    d3.select(button).classed('btn-primary', true)
    drawGraph(nodes, edgesForMode(mode))


  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))
