class window.Ajax
  
  referer: false
  
  loadSettingsPage: ->
    _session.query '/settings/', {}, (data) ->
      _ajax.setArchor '/settings/'
      _page.renderSettings data
      false
    false
  
  load404Page: ->
    $.get '/404.html', (data) ->
      $('.data-container .inner').html data
    false
  
  loadAboutPage: ->
    $.get '/templates/about.html', (data) ->
      _page.renderTextpage data
      _ajax.setTitle 'About'
    false
  
  setArchor: (anchor) ->
    @referer = this.getAnchor()
    window.location.hash = '#' +anchor
  
  getAnchor: () ->
    window.location.hash.substring 1;
  
  setTitle: (title) ->
    document.title = title+ ' @ BeatHaven'
    
  go: (url) ->
    this.setArchor url
    false

  detectPage: () ->
    if m = _ajax.getAnchor().match /\/artist\/(.+)\//
      _search.loadArtistData m[1]
    else if _ajax.getAnchor() == '' or _ajax.getAnchor().match /\/search\//
      #_ajax.loadSearchPage();
    else if _ajax.getAnchor().match /\/settings\//
      _ajax.loadSettingsPage()
    else if _ajax.getAnchor().match /\/about\//
      _ajax.loadAboutPage()
    else
      #_ajax.loadSearchPage()
    false

$(window).bind 'hashchange', ->
  #_ajax.detectPage()
  false