var visibleTags = $('span.tag:visible');

visibleTags.each(function() {
  var tag = $(this);
  var position = tag.position();
  var left = tag.position().left;

  tag.css({
    right: 'auto',
    left: left,
    background: 'red',
    cursor: 'pointer'
  });
});

visibleTags.draggable({
  stop: function(e, ui) {
    var pos = ui.helper.position();
    var update = {
      id: ui.helper.data('room'),
      tagXPosition: 576 - pos.left - ui.helper.outerWidth() - 2,
      tagYPosition: ui.helper.css('top').slice(0, -2)
    };
    console.log(update);
    $.ajax({
      url: '/d/room/update_batch',
      type: 'post',
      data: { updates: JSON.stringify([update]) }
    })
  }
});