 d3.select(window)
   .on('keydown', -> setInterval rotate, 10 if d3.event.which == 27)
   .on('load', init)
-  
+

urls =
  search: (q) ->
    "http://en.wikipedia.org/w/api.php?" +
    "action=query&" + 
    "list=search&" + 
    "srprop=links&" +
    "format=json&" + 
    "callback=__cb__&" +
    "srsearch=" + q
  relevance: (q) ->
    "action=query&" +
    "prop=categories&" + 
    "format=json&" +
    "callback=__cb__&" + 
    "titles=" + query 
                  
jsonp =  (query, callback) ->
  window.__cb__ = callback or -> log(arguments)
  d3.select('head').append('script').attr('src', urls.search(query))
  
mirror = (f) ->
  if "function" != typeof f then f = d3.ease.apply(d3, arguments) 
  (t) -> if t < .5 then f(2 * t) else f(2 - 2 * t) 

rand_c = ->
  '#' + (0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6)

  d3.select(@).attr
    cx: (d) -> d.x += dx
    cy: (d) -> d.y += dy

  d3.selectAll('line').attr
    x1: (d) -> d.from.x
    y1: (d) -> d.from.y
    x2: (d) -> d.to.x
    y2: (d) -> d.to.y

  d3.selectAll('text').attr
    x: (d) -> d.x
    y: (d) -> d.y

distance = (x1, y1, x2, y2) ->
  xd = x1 - x2
  yd = y1 - y2
