function fix_ie_overflow() {
  if (!/*@cc_on!@*/0) return;

  $$('div.highlight').each(function(element) {
    if (element.scrollWidth > element.offsetWidth) {
      element.setStyle({ height: '2em', overflowY: 'hidden' });
    }
  });
}

document.observe('dom:loaded', function() {
  var page = window.location.pathname;
  $$('#navigation li a').first().addClassName('active');
  if (page != '/') {
    $$('#navigation li a').each(function(element) {
      if (element.href.match(page)) {
        $$('#navigation li a').invoke('removeClassName', 'active');
        element.addClassName('active');
      }
    });
  }

  var posts = $$('ul.limit li');

  function show_all() {
    posts.invoke('show');
  }

  function hide_posts() {
    $('toggle_posts').innerHTML = '&rarr; Show all #{count} posts'.interpolate({ count: posts.length });
    posts.slice(8, -1).invoke('hide');
  }

  if ($('toggle_posts')) {
    hide_posts();
  
    $('toggle_posts').observe('click', function(e) {
      var element = Event.element(e);
      if (element.hasClassName('all')) {
        element.removeClassName('all');
        element.innerHTML = '&larr; Show less';
        show_all();
      } else {
        element.addClassName('all');
        hide_posts();
      }
      Event.stop(e);
    }.bind(this));
  }

  fix_ie_overflow();
});
