(function(global) {
  var fuse = global.fuse, $ = fuse.query;

  var words = [
    'community',
    'deadlines',
    'features',
    'flexibility',
    'free time',
    'performance',
    'plugins',
    'stability'
  ];

  function handleShowcaseLinkClick(e) {
    e.stop();

    var target = e.getCurrentTarget(), delegator = e.getDelegator(),
      itemName = target.getAttribute('class');

    delegator.query('li').removeClassName('active');
    target.up('li').addClassName('active');

    delegator
      .next('.showcase-items')
      .query('.showcase-item')
      .removeClassName('active')
      .filter(function(el){
        return fuse(el).match('.' + itemName);
      }).addClassName('active');
  }

  fuse(document).observe('dom:loaded', function() {
    var index = Math.floor(Math.random() * (words.length)),
      sloganWord = $('#slogan_word');

    sloganWord.update(words[index] + '.');

    $('.showcase-list').delegate('click', 'a', handleShowcaseLinkClick);
  });
})(this);
