document.observe( 'dom:loaded', function() {
	$$('div#container div#header ul li a').each( function( e ) {
		$(e).observe( 'mouseover', function(ev) {
			if( !$(this.parentNode).hasClassName( 'active' ) ) {
				$(this.parentNode).morph( 'margin-top: 10px;', {duration: .2, afterFinish: function() {
					$(e.parentNode).toggleClassName( 'selected' );
				}});
				$(this.parentNode).down( 'a' ).morph( 'opacity: 1; font-weight: bold;' );
			}
		});

		$(e).observe( 'mouseout', function() {
			if( !$(this.parentNode).hasClassName( 'active' ) ) {				
				$(this.parentNode).morph( 'margin-top: 0px;', {duration: .2, afterFinish: function() {
					$(e.parentNode).toggleClassName( 'selected' );
				}});
			}
		});
	});

	$$('.totop').each( function( e ) {
		$(e).observe( 'click', function( ev ) {
			$('pagetop').scrollTo();
			Event.stop( ev );
		});
	});
	
	$$('a[href!=""]').each(function(link){
        var siteregex = /^(http:\/\/)([a-z]*\.)?(paboweb.nl)/i;
        if((  link.readAttribute('href').startsWith('http://') || 
              link.readAttribute('href').startsWith('https://') ) &&
              !link.readAttribute('href').match(siteregex)){
            link.writeAttribute('target','_blank');
            link.writeAttribute('onClick','return !window.open(this.href);');
            link.writeAttribute('rel','external');
        }
  });

  $$('a[rel="external"]').each(function(link){
      if(link.readAttribute('href') != '' && link.readAttribute('href') != '#'){
          link.writeAttribute('target','_blank');
      }
  });
});
