           window.location.replace '/'
         cookie = $.cookie 'clientId'
 
-    # Finding vendor prefixes
-    getVisibilityProperty = ->
-      prefixes = ["webkit", "moz", "o"]
-      return "hidden" if `"hidden" in document`
-      return "#{prefix}Hidden" for prefix in prefixes when `prefix + "Hidden" in document`
-      return null
-
-    isHidden = -> Boolean document[getVisibilityProperty()]
-
-    getVisibilityEventName = ->
-      return "#{getVisibilityProperty().replace(/[Hh]idden/, '')}visibilitychange"
-
     document.addEventListener getVisibilityEventName(), (event)=>
-      @visibilityChange event, isHidden()
+      @focusChange event, isFocused()
 
   addUnloadListener:(listener)-> @unloadListeners.push listener
 
-  addVisibilityListener: (listener)-> @visibilityListeners.push listener
-
-  visibilityChange: (event, state)->
+  addFocusListener: (listener)-> @focusListeners.push listener
+
+  focusChange: (event, state)->
 
     return unless event
-    listener state, event for listener in @visibilityListeners
+    listener state, event for listener in @focusListeners
 
   beforeUnload:(event)->
 

    @scrollingEnabled      = yes
    @layers                = []
    @unloadListeners       = []
    @visibilityListeners   = []

    @bindEvents()
    @setWindowProperties()

  superKey        = if navigator.userAgent.indexOf("Mac OS X") is -1 then "ctrl" else "command"
  addListener     = (eventName, listener, capturePhase=yes)->
    document.body.addEventListener eventName, listener, capturePhase

  # Finding vendor prefixes for visibility
  getVisibilityProperty = ->
    prefixes = ["webkit", "moz", "o"]
    return "hidden" if `"hidden" in document`
    return "#{prefix}Hidden" for prefix in prefixes when `prefix + "Hidden" in document`
    return null

  isFocused = -> Boolean document[getVisibilityProperty()]

  getVisibilityEventName = ->
    return "#{getVisibilityProperty().replace(/[Hh]idden/, '')}visibilitychange"

  constructor:(options,data)->

