+historyCache = []
 visit = (url) ->
   if browserSupportsPushState?
     reflectNewUrl url


if browserSupportsPushState
  rememberInitialPage()
  
  window.addEventListener 'popstate', (event) ->
    if event.state?.turbolinks
      fetchReplacement document.location.href

  document.addEventListener 'click', (event) ->
    handleClick event

  xhr.onabort = -> console.log("Aborted turbolink fetch!")
  xhr.send()

fetchHistory = (url) ->
  while(historyCache.length > 0)
    cache = historyCache.pop()
    if cache.url == url
      replaceHTML cache.html
      triggerPageChange
      return

  fetchReplacement url

fullReplacement = (html, url) ->
  replaceHTML html, "cache"
  triggerPageChange()

reflectNewUrl = (url) ->
