Event.observe(document, 'dom:loaded', attachHandlers)

function attachHandlers(event) {
  $('troubleshooting').down('ul.menu').select('a').each(function (elem) {
    elem.observe('click', toggleTroubleshooting)
  })
  
  $('installingLink').up().addClassName('on')
  $('starting').hide()
  $('using').hide()
  
  $('quotes').select('div').each(function (elem) {
    elem.hide()
  })
  $('quotes').down('div').show()
  
  new PeriodicalExecuter(showQuote, 3)
}

function showQuote() {
  var currentQuote = null
  $('quotes').select('div').each(function (elem) {
    if (elem.visible()) {
      currentQuote = elem
    }
  })
  
  var nextQuote = null
  if (currentQuote.nextSiblings().size() == 0) {
    nextQuote = $('quotes').down('div')
  }
  else {
    nextQuote = currentQuote.nextSiblings()[0]
  }
  
  currentQuote.fade()
  nextQuote.appear()
}

function toggleTroubleshooting(event) {
  var aElem = event.element()
  var divName = aElem.id.replace(/Link/, '')

  aElem.up('td').select('div.section').each(function (elem) {
    elem.hide()
  })
  aElem.up('ul').select('li').each(function (elem) {
    elem.removeClassName('on')
  })
  
  aElem.up().addClassName('on')
  $(divName).show()
  
  event.stop()
}