document.observe('dom:loaded', function(event){
  $$('a[href*="#"]').each(function(anchor){
	anchor.observe('click', function(event) {
	  var theDivID 	   = this.href.split('#')[1];
	  var pageAnchor   = $$('[id~="#{href}"]'.interpolate({href: theDivID})).first();
	  var delta        = pageAnchor.offsetTop - document.viewport.getScrollOffsets().top;
	  var updateUrl    = function(){ location.href = this.href }.bind(this);
	  new Effect.Scroll(window, { y: delta, afterFinish: updateUrl, duration: 0.4 });
	  if(theDivID!='top'){ new Effect.Highlight(theDivID, { duration: 1.8 }); }
	  Event.stop(event);
	});
  });
});

Event.observe(window, 'load', function() {
    $$('a[rel="external"]').each(function(link){
        if(link.readAttribute('href') != '' && link.readAttribute('href') != '#'){
            link.writeAttribute('target','_blank');
        }
    });
});