   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)->
 

          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()

  addUnloadListener:(listener)-> @unloadListeners.push listener

  addVisibilityListener: (listener)-> @visibilityListeners.push listener

  visibilityChange: (event, state)->

    return unless event
    listener state, event for listener in @visibilityListeners

  beforeUnload:(event)->


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

    @bindEvents()
    @setWindowProperties()
