if( window.jQuery )  // Avoid more errors in IE 5.0
{
  // Directly set flag for CSS to indicate JavaScript is enabled.
  // At this point "HTML" is the only accessable element.
  $(document.documentElement).addClass("jsEnabled");

  $(document).ready( function()
  {
    // -------------------------------
    // Fix links

    // Geef links met rel="external" een target="_blank" attribuut.
    $(document.links).filter('[href][rel=external]').each(function() { this.target = '_blank'; });


    // --------------------------------
    // Form input label flip

    // Activeer 'overlabels' over compacte formulieren zoals het zoekscherm
    $('label.overlabel')
      .each( function()
      {
        // Get field
        var label = $(this);
        var id    = this.htmlFor || this.getAttribute('for');
        var field = null;
        if( ! id || ! (field = document.getElementById( id ) ) ) return;

        // Implement show/hide effect
        $(field).addClass("overlabel-js")                 // for setTimeout() below
                .focus( function() { label.hide(); } )
                .blur ( function() { this.value === '' && label.show(); } );

        // Also for mouse click
        label.mousedown( function() { field.focus(); } );
      } );

    // Hide overlabels after the form is auto-filled in by the browser.
    setTimeout( function()
    {
      var fields = $("input.overlabel-js");
      var labels = $("label.overlabel");
      fields.each( function() { this.value !== '' && labels.filter("[for=" + this.id + "]").hide(); } );
    }, 50 );

  } );
}
