 CI.ajax.init()
 
-setInner = =>
+display = (template, args, subpage, hash) ->
   $('html').removeClass('outer').removeClass('new-outer').addClass('inner')
-
-display = (template, args) ->
-  setInner()
   $('#main').html(HAML[template](args))
+  if subpage
+    $('#subpage').html(HAML["#{template}_#{subpage}"](args))
+    $("##{subpage}").addClass('active')
+  if $('#hash').length
+    $("##{hash}").addClass('active')
+    $('#hash').html(HAML["#{template}_#{subpage}_#{hash}"](args))
+
   ko.applyBindings(VM)
 
 splitSplat = (cx) ->

    else
        VM.loadExtraEditPageData subpage

    setInner()
    $('#main').html(HAML['edit']({project: project_name}))
    $('#subpage').html(HAML['edit_' + subpage]({}))
    ko.applyBindings(VM)


  loadAccountPage: (cx, [subpage, hash]) =>
    subpage or= "notifications"

    else if subpage is "api"
      @current_user().load_tokens()

    display "account", {}, subpage, hash


  renderAdminPage: (subpage) =>
    display "admin", {}, subpage

  loadAdminPage: (cx) =>
    @renderAdminPage ""
