             height: viewport.height
             width: viewport.width
 
-          $pageDisplay.attr
-            height: viewport.height
-            width: viewport.width
-
           $textLayerDiv = $('<div/>').addClass('display-text').css(
             height: viewport.height + 'px'
             width: viewport.width + 'px'
           ).appendTo $pageDisplay
 
-          $pageDisplay.css
-            position: 'relative'
-
           $closestTextDiv = null
           closestDistance = Number.MAX_VALUE;
 


            closestDistance = Number.MAX_VALUE;
            $textLayerDiv.children().each ->
              textDivOffset = $(this).data("cachedOffset")
              textDivWidth = $(this).data("cachedWidth")
              textDivHeight = $(this).data("cachedHeight")

              distXLeft = relX - textDivOffset.left
              distXRight = relX - (textDivOffset.left + textDivWidth)
              distXCenter = relX - (textDivOffset.left + textDivWidth/2.0)

              distYTop = relY - textDivOffset.top
              distYBottom = relY - (textDivOffset.top + textDivHeight)
              distYCenter = relY - (textDivOffset.top + textDivHeight/2.0)


              distX = if Math.abs(distXLeft) < Math.abs(distXRight) then distXLeft else distXRight
              if relX > textDivOffset.left and relX < textDivOffset.left + textDivWidth
                distX = 0

              distY = if Math.abs(distYTop) < Math.abs(distYBottom) then distYTop else distYBottom
              if relY > textDivOffset.top and relY < textDivOffset.top + textDivHeight
                distY = 0
              # distY = if Math.abs(distY) < Math.abs(distYCenter) then distY else distYCenter


    Meteor.subscribe 'annotations-by-publication', Session.get 'currentPublicationId'
    Meteor.subscribe 'comments-by-publication', Session.get 'currentPublicationId'

# This function should work on rotated elements as well for all values
getElementPosition = (element) ->
  dims =
    left: 0
    top: 0
    right: 0
    bottom: 0
    width: 0
    height: 0

  if element
    rect = element.getBoundingClientRect()
    parentRect = $(element).parent().get(0).getBoundingClientRect()
    dims.left = rect.left - parentRect.left
    dims.top = rect.top - parentRect.top
    dims.right = rect.right - parentRect.right
    dims.bottom = rect.bottom - parentRect.bottom

    if rect.width
      dims.width = rect.width
      dims.height = rect.height
    else
      dims.width = dims.right - dims.left
      dims.height = dims.bottom - dims.top

  dims

displayPublication = (publication) ->
  PDFJS.getDocument(publication.url()).then (pdf) ->
    for pageNumber in [1..pdf.numPages]
      $canvas = $('<canvas/>').addClass('display-canvas')
