         if not data.data["logged_in"]
           window.location.href = "/login"
 
-window.redirectIfLoggedIn = ->
+@redirectIfLoggedIn = ->
   apiCall "GET", "/api/user/status", {}
   .done (data) ->
     switch data["status"]

      style = "success"
  return style

window.apiNotify = (data) ->
  style = getStyle data
  $.notify data.message, style


@apiCall = (type, url, data) ->
  $.ajax {url: url, type: type, data: data, cache: false}
  .fail (jqXHR, text) ->
    $.notify "API is offline. :(", "error"

@redirectIfNotLoggedIn = ->
  apiCall "GET", "/api/user/status", {}
  .done (data) ->
    switch data["status"]
