   xhr.send()
 
 fetchHistory = (state) ->
+  rememberPage()
   cache = historyCache[state.position]
   if cache
     replaceDocument cache.body, cache.title
     triggerPageChange
-    window.scrollTo(cache.scrollLeft,cache.scrollTop)
+    window.scrollTo(cache.pageXOffset,cache.pageYOffset)
   else
     fetchReplacement document.location.href
 

  replaceDocument doc.body,title?.textContent, 'cache'


replaceDocument = (body,title,cache) ->
  originalBody = document.body
  document.documentElement.appendChild body, originalBody
  document.documentElement.removeChild originalBody
  document.title = title
  historyCache[window.history.state.position] = {url:document.location.href,body:body,title:title} if cache



extractLink = (event) ->


historyCache = []
lastState = null
visit = (url) ->
  if browserSupportsPushState? and document.location.href != url
    rememberPage()
    reflectNewUrl url
    fetchReplacement url
  else
    document.location.href = url

rememberPage = ->
  historyCache[lastState.position] = url: document.location.href, body: document.body, title: document.title, pageYOffset: window.pageYOffset, pageXOffset: window.pageXOffset

fetchReplacement = (url) ->
  xhr = new XMLHttpRequest
