/*
  This script contains all the functions that we need 
  to use the jQuery Tools in this website.
  
  $j will be the reference to jQuery
  ==================================
*/
  var $j = jQuery.noConflict();

/* 
  First some extra functions and inits
*/
  // Supersize : init
  $j(function(){$j.fn.supersized.options = {
    startwidth: 640,
    startheight: 479,
    vertical_center: 0,
    slideshow: 0,
    navigation:0,
    transition: 0,
    pause_hover: 0,
    slide_counter: 1,
    slide_captions: 0,
    slide_interval: 10000
    };
  });
  
  // Supersize the background as soon as it is available
  // So do not wait for document to be ready for this!
  $j('#supersize').supersized(); 
  
  // Carousel : Clone the H2 to another DIV and hide the original
  function swapperdeSwap(myIndex){
    var myItem   = $j('#showcaseOne .items .carousel-item').eq(myIndex);
    var myHeader = $j(myItem.find('h2')).text();
    $j('#footer-title').html('<h2>'+myHeader+'</h2>');
    $j(myItem.find('h2')).css('display','none');
    return;
  };

/*
  Run the scripts when the document is loaded
*/
$j(document).ready(function() {

  // The Carousel : Treat the first item as if it was seeked on page load
  swapperdeSwap(0);

  // The Carousel 
  $j("#showcaseOne").scrollable({
    size:1,
    item:'div.carousel-item',
    onSeek: function(){ 
      var myIndex = this.getIndex()+1;
      swapperdeSwap(myIndex);
    }
  }).autoscroll({steps:1,interval:8500}).circular();

  // The overlay used for "Geschiedenis"
  $j(".geschiedenis a[rel]").overlay({ 
    top: '11%',
    expose: {
      color: '#333',
      loadSpeed: 200,
      opacity: 0.8
      }, 
    closeOnClick: true,
    closeOnEsc: true,
    onBeforeLoad: function() { 
      // grab wrapper element inside content 
      var wrap = this.getContent().find(".contentWrap"); 
      // load the page specified in the trigger 
      wrap.load(this.getTrigger().attr("href")); 
    }
  });
}); // document ready?