 ---
 ---
+today = new Date()
+currentYear = today.getFullYear()
+hashInfo = []
+calendarData = {}
+prefix = ''
+
+getHash = ->
+  if document.location.hash != ''
+    hashInfo = document.location.hash.slice(1).split('/')
+  else
+    hashInfo = []
+
+scrollTo = (hash) ->
+  setTimeout(->
+    el = document.getElementById(hash.slice(1))
+
+    if el
+      parent = if el.nodeName == 'H2'
+        el.parentElement.parentElement
+      else
+        el.parentElement
+
+      parent.scrollIntoView({behavior: 'smooth', block: 'start'})
+  , 0)
+
 slugify = (name) ->
   # TODO: Enhance slugification
   name.toLowerCase().replace(/[^\w]/g, '-')
 
+humanizeDate = (date, type) ->
+  return date unless date
+
+  if date.match ' '
+    dateParts = date.split ' '
+    dateTime = dateParts[0] + 'T' + dateParts[1]
+
+    if type == 'start'
+      format = '%a %e %b %Y %l:%M%P'
+    else 
+      format = '%l:%M%P ' + dateParts[2]
+  else
+    dateTime = date
+    format = '%A %e %B'
+    format += ' %Y' unless +date.slice(0,4) == currentYear
+
+  new Date(dateTime).toLocaleFormat(format)
+
+makeQuickLinks = (allConfs) ->
+  $lis = $('h2.event>a', allConfs).clone().map((el) ->
+    @['title'] = ''
+    $('<li>').append(@)[0]
+  )
+
+  $ul = $('<ul>').append($lis)
+
+  $("""
+    <div id="#{prefix}quicklinks" class="quicklinks">
+      <h2>Quicklinks</h2>
+    </div>
+    """).append($ul)
+
 processAllEvents = (events) ->
-  today = Date.now()
   formatted = []
 
   for year of events

  # TODO: Dynamically load by year (so not all events are loaded at once)
  yearData = '//rhevents-duckosas.rhcloud.com/all.json'

  now = Date.now()

  # Grab and format events
  $.get yearData, processCalendar


        event['title'] = event['name']

        event['current'] = new Date(event['end']) > today

        event['className'] = if event['current']
          "current"
        else
          "old"
