Move counter init code into separate function
Put counter JS settings into renderable array

Instead of manually calling drupal_add_js() function, it is possible to
used the '#attached' property of renderable arrays to specify all
required JS files and settings.