       $(e.target).parents('.page').nextAll().remove() unless e.shiftKey
       scrollTo createPage(name).appendTo('.main').each refresh
       # FIXME: can open page multiple times with shift key
-      
+
       if History.enabled
         setState {pages: pagesInDom(), active: name}
 

    target = el.position().left
    width = el.outerWidth(true)
    contentWidth = $(".page").outerWidth(true) * $(".page").size()
  
    if target < minX
      $("body").animate scrollLeft: target
    else if target + width > maxX
      $("body").animate scrollLeft: target - ($("body").width() - width)
    else if maxX > $(".pages").outerWidth()
      $("body").animate scrollLeft: Math.min(target, contentWidth - $("body").width())
      
      
# PLUGINS for each story item type

  window.plugins =

    .ajaxError (event, request, settings) ->
      console.log [event,request,settings]
      $('.main').prepend "<li class='error'>Error on #{settings.url}<br/>#{request.responseText}</li>"

  $('.main')
    .delegate '.show-page-source', 'click', (e) ->
      e.preventDefault()
      #TODO: this is a cut,paste&hack from a few lines above - refactor out
      if useLocalStorage() and json = localStorage[pageElement.attr("id")]
        #set the dialog content..
        window.dialog.dialog('open');
