   selector = null 
   interval = null
    
+  updateElement= (element) ->
+    $element = $(element)
+    url = $element.data('updatePath')
+    return unless url
+         
+    $.ajax
+      url: url,
+      dataType: 'html',
+      data: {'polling_service': true},
+      success: ( data, textStatus, jqXHR ) ->
+        console.log 'success'
+        # try to get loacation from response header 
+        redirectTo = jqXHR.getResponseHeader('Location')
+        # response is a redirect
+        if redirectTo 
+          # redirect url is equal to auth path
+          if redirectTo.indexOf('/auth/login/')>-1
+            # just reload to avoid redirect to a no layout page after login
+            window.location.reload()
+          else
+            # redirect to the redirectTo url
+            window.location = redirectTo
+        else
+          # no redirect -> replace content with html from response
+          #exists = $.contains(document.documentElement, $element)
+          $element.replaceWith(data)
+          
+     
   # update method which is called periodically 
   update= () ->    
     # get current timestamp

      
      # modulo operation: rest of current timestamp divided by element's interval should be zero
      shouldUpdate = (timestamp % Math.round(updateInterval/ interval))==0

      if shouldUpdate
        # update content
        $.ajax
          url: url,
          dataType: 'html',
          data: {'polling_service': true},
          success: ( data, textStatus, jqXHR ) ->
            # try to get loacation from response header 
            redirectTo = jqXHR.getResponseHeader('Location')
            # response is a redirect
            if redirectTo 
              # redirect url is equal to auth path
              if redirectTo.indexOf('/auth/login/')>-1
                # just reload to avoid redirect to a no layout page after login
                window.location.reload()
              else
                # redirect to the redirectTo url
                window.location = redirectTo
            else
              # no redirect -> replace content with html from response
              #exists = $.contains(document.documentElement, $element)
              $element.replaceWith(data)
            
  # initialize the service          
  @init= (options={}) ->

    interval = interval*1000 if interval < 1000
    
    # start update with interval
    setInterval update, interval
    
  @update= (name) ->
    $("*[data-update-path*='#{name}']").each () -> updateElement(this)

      
    