-window.historyCache = []
-window.testArray = []
+@historyCache = []
+
 visit = (url) ->
   if browserSupportsPushState?
+    @historyCache.push({url:document.location.href,body:document.body,title:document.title})
     reflectNewUrl url
     fetchReplacement url
   else


replaceDocument = (body,title,cache) ->
  originalBody = document.body
  document.documentElement.appendChild body.cloneNode(true), originalBody
  document.documentElement.removeChild originalBody
  document.title = title
  window.historyCache.push({url: document.location.href, title:title,body:body}) if cache


extractLink = (event) ->

  xhr.send()

fetchHistory = (url) ->
  while(@historyCache.length > 0)
    cache = @historyCache.pop()
    if cache.url == url
      replaceDocument cache.body, cache.title
      triggerPageChange
