-saveGraph = () ->
+saveGraph = ->
   graph = {}
   graph.entities = getCurrentEntities()
   graph.relationships = getCurrentRelationships()

    entity_y      = parseInt( $(element).attr("data-y"))
    $(element).dialog({ width: entity_width, height: entity_height, position: [entity_x,entity_y] })

  $("#settings").hide()

  $("#save_button").click -> saveGraph()

  alerts = 0

  addRelationshipsToDOM

  $('.entity').on 'dialogdrag', (event, ui) ->

    alerts += 1
    console.log( "Moving entity " + event.currentTarget.dataset.id ) if alerts % 30 == 0
    
    x1 = ui.position.left
    y1 = ui.position.top - $('#header_bar').height()
    x2 = 0 # window.relationships[] # which entity is being dragged??
    y2 = 0 # window.relationships[]
    $('#relationship1').attr('d', "M #{x1} #{y1} L #{x2} #{y2}")


  else
    $.ajax({ url:"/graphs", type:"POST", dataType:"json", data:encodeData })

getCurrentEntities = ->
  entities = []
  $("div.ui-dialog").each (index, element) ->
    entities[index] = {}
