+draggingViewport = false
+
 class @Publication extends @Publication
   constructor: (args...) ->
     super args...


Template.publicationScroller.created = ->
  $(window).on 'scroll.publicationScroller', (e) =>
    $(@find '.viewport').css 'top', "#{ viewportPositionPercentage() }%"

Template.publicationScroller.rendered = ->
  if Session.equals 'currentPublicationRendered', true
    $(@find '.viewport').draggable
      containment: 'parent'
      stop: (e) ->
        e.stopPropagation()
        console.log e
        scrollToOffset e.pageY - $(e.target).parent().offset().top
    $(@find '.viewport').height "#{ viewportHeightPercentage() }%"

Template.publicationScroller.destroyed = ->

Template.publicationScroller.events
  'click': (e, template) ->
    $target = $(e.target)
    offset = if $target.is('#scroller') then e.offsetY else $target.offset().top - $target.parent().offset().top
    scrollToOffset offset

Template.publicationAnnotations.annotations = ->
