

function openShortcut( theUrl )
{
  if( ( theUrl.substring(0,1) != '/' ) )
  {
    window.open( theUrl,'', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes' );
  }
  else
  {
    location.href = theUrl;
  }
}


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() {


    // -------------------------------
    // Slider homepage
    $(function() {
        setInterval( "slideSwitch()", 5000 );
    });

    // -------------------------------
    // Menu newsitem fades
    // Make sure this runs first, no text jumping.

    curNewsItem = 0;

    var newsTimer = null;

    if( typeof newsList != "undefined" && newsList.length > 0 )
    {
      $("#newsticker a").text( newsList[ curNewsItem ].title );
      $("#newsticker a").attr("href", newsList[curNewsItem].link);
      newsTimer = window.setTimeout(refreshNews, 3000);
    }


    function setNextNewsItem ()
    {
      curNewsItem++;
      if(curNewsItem > newsList.length - 1)
      {
        curNewsItem = 0;
      }

      $("#newsticker a").text(newsList[curNewsItem].title);
      $("#newsticker a").attr("href", newsList[curNewsItem].link);
      return false;
    }

    function refreshNews()
    {
      $("#newsticker p").fadeOut("slow", setNextNewsItem).fadeIn("slow");
      newsTimer = window.setTimeout(refreshNews, 5000);
    }


    // ----------- Add hover effect for IE 6.0

    if( jQuery.browser.msie )
    {
      // Define actions only once
      var addHover     = function(e) { $(this).addClass("hover"); };
      var removeHover  = function(e) { $(this).removeClass("hover"); };

      // Apply to all elements needed:
      $("#testimonials dl").hover( addHover, removeHover );
    }

    // Make sure the button hover effect is applied to the child too
    // (when entering mouse at the left). Also fixes IE6 hover.
    $("#contentboxform p.button, form.standardform p.button, div.standardform p.button").hover(
      function(e) { $(this).addClass("button-hover").find("input").addClass("hover");       }  // mouse over
    , function(e) { $(this).removeClass("button-hover").find("input").removeClass("hover"); }  // mouse out
    );


    // --------- Pulldown items automatisch redirecten bij onChange

    $("select.selectitem").change( function()
    {
      window.location.href = $(this).val();
    });


    // --------- Fix links

    // Geef links met rel="external" een target="_blank" attribuut.
    $(document.links).filter('[href][rel=external]').attr("target", "_blank");


    // --------- Make home height consistent

    // Avoid css hacks, or dependencies on newer CSS code which old browsers don't support.

    var height01 = document.getElementById('height01');
    if( height01 != null )
    {
      var height02 = document.getElementById('height02');
      var height03 = document.getElementById('height03');

      var highest = 0;
      var reduce = [];
      var boxes  = [ height01, height02, height03 ];
      for( var i = 0; i < boxes.length; i++ )
      {
        var boxHeight = boxes[ i ].offsetHeight;

        // Track size to substract later.
        var button  = $( boxes[ i ] ).siblings(".button");
        reduce[ i ] = ( button.length == 0 ) ? 0 : button[0].offsetHeight;

        if( boxHeight + reduce[i] > highest )
        {
          highest = boxHeight + reduce[i];
        }
      }

      if( jQuery.browser.msie && jQuery.browser.version < 7 )
      {
        height01.style.height = ( highest - reduce[0] ) + "px";
        height02.style.height = ( highest - reduce[1] ) + "px";
        height03.style.height = ( highest - reduce[2] ) + "px";
      }
      else
      {
        height01.style.minHeight = ( highest - reduce[0] ) + "px";
        height02.style.minHeight = ( highest - reduce[1] ) + "px";
        height03.style.minHeight = ( highest - reduce[2] ) + "px";
      }
    }


    // --------------------------------
    // 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() { setTimeout( function() { field.focus(); }, 20 ); } );
      }
    );

    // 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 );


    // -------------------------------
    // Testimonials

    // Expand testimonials
    if( document.getElementById('testimonials') != null )
    {
      $("#testimonials .quote").click(
        function(e) { $(this).next(".text").toggle(); return false; }
      );

      // If testimonial selected by queystring then try to show text of that testimonial
      if( location.hash.substring(0, 7) == "#intro_" )
      {
        var introBox = $( document.getElementById( location.hash.substring(1) ) );  // avoid jQuery magic (e.g. looking for '.doc' class)
        if( introBox.length != 0 )
        {
          // The box is also expanded with CSS if the browser supports :target.
          introBox.find(".text").show();
          setTimeout( 'window.scrollTo( 0, ' + introBox.offset().top + ' );', 50 );
        }
      }

      // Make sure an internal widget link triggers the expand effect too, not only jump to the element.
      var links = $("#column p.button > a[href*=#intro_]");
      links.click( function()
      {
        var pos = this.href.indexOf("#intro_");
        if( pos != -1 )
        {
          var introBox = $( document.getElementById( this.href.substring( pos + 1 ) ) );
          if( introBox.length != 0 )
          {
            // Found referenced element in this page.
            introBox.find(".text").show();
            setTimeout( 'window.scrollTo( 0, ' + introBox.offset().top + ' );', 50 );
            return false;
          }
        }
      } );
    }


    // --------------------------------
    // Thickbox CSS

    // Load thickbox CSS only when needed.
    if( window.tb_init != null )
    {
      $('head').append( '<link href="/resources/css/thickbox.css" rel="stylesheet">' );
    }


    // --------------------------------
    // news items clickable and add hover class for pointer as cursor

    $("#news dl").click( function(e)
    {
      window.location.href = $(this).find("dt a").attr("href");
    });

    // Define actions only once
    var addNewsHover     = function(e) { $(this).addClass("hover"); };
    var removeNewsHover  = function(e) { $(this).removeClass("hover"); };

    // Apply to all elements needed:
    $("#news dl").hover( addNewsHover, removeNewsHover );

    // activate sharethis button if contained on page
    stLight.options({publisher:'835809c0-cfa5-4ff2-8314-d7b5cb24c356'});
  } );
}



function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
