sort images by distance, reposition buttons