 
 class AppsController
   constructor: ->
+    window.toggleAppsGroups()
     @updateAppsVersions()
 
   updateAppsVersions: ->
     $(".app-title").each (idx, elem) ->
-      master_version = $(elem).find('.version-value')
-      if master_version.length
-        master_version = master_version.text()
-
+      master = $(elem).find('.version-value')
+      if master.length
+        master = master.text()
         ul = $(elem).next('ul')
         ul.find('li').each (idx2, elem2) ->
           element = $(elem2)
           urn = element.find('.app-name a').text()
-          url = "//#{urn}.herokuapp.com/g5_ops/health"
           ver = element.find('.version')
-          $.ajax url,
-            method: 'GET'
-            success: (res, status, xhr) ->
-              version = if res.version then res.version else res.health.version
-              if version == master_version
-                klass = 'current'
-              else if version > master_version
-                klass = 'ahead'
-              else if version < master_version
-                klass = 'behind'
-              ver.find('.version-value').html("<b class='#{klass}'>#{version}</b>")
-            error: (xhr, status, err) ->
-              ver.find('.version-value').html("<b class='error'>not found</i>")
+          window.ajaxVersion(urn, master, ver)
+
 
 class OrgsController
   constructor: ->
+    window.toggleAppsGroups()
     @updateOrgsVersions()
 
   updateOrgsVersions: ->

        $(title).addClass('show')
        $(title).next('.app-list').addClass('show')

$(document).ready ->
  window.toggleAppsGroups()
  if $('.app').hasClass('orgs')
    window.orgsController = new OrgsController
  else

        ver = element.find('.version')
        if ver.length
          urn = element.find('.app-name a').text()
          master = ver.find('.master-version').text()
          window.ajaxVersion(urn, master, ver)
