j$(document).ready(function() {
  j$().fancybox({
    selector: '.multibox',
    arrows: false,
    infobar: false,
    buttons: [
      'close'
    ],
    caption: function(instance, item) {
      return j$(this).find('.caption').html();
    },
    lang: 'nl',
    i18n: {
      nl: {
        CLOSE: "Sluiten",
        NEXT: "Volgende",
        PREV: "Vorige",
        ERROR: "De opgevraagde content kon niet worden geladen. <br/> Probeer later opnieuw.",
        PLAY_START: "Diavoorstelling starten",
        PLAY_STOP: "Diavoorstelling pauzeren",
        FULL_SCREEN: "Volledig scherm",
        THUMBS: "Miniaturen",
        DOWNLOAD: "Downloaden",
        SHARE: "Delen",
        ZOOM: "Zoom"
      }
    }
  });
});


var recallAutoloadCooldown = false;

j$(document).ready(function()
{
  j$(document).on('click', '[data-recall-accept~="refresh"], [data-recall-accept~="refreshRemote"]', function (event)
  {
    
    event.preventDefault();
    
    if (j$(this).is('[data-recall-accept~="refreshRemote"]'))
    {
      return recallDoCall(this, 'refreshRemote');
    }
    else
    {
      return recallDoCall(this, 'refresh');    
    }
  });

  j$(document).on('click', 'a[data-recall]', function (event)
  {
    var returnVal = true;

    if (j$(this).is('[data-recall~="getRemote"]'))
    {
      returnVal = recallDoCall(this, 'getRemote');
    }
    else
    {
      returnVal = recallDoCall(this, 'get');    
    }

    if (returnVal == false)
    {
      
      event.preventDefault();
    }
  });

  j$(document).on('submit', ':has(> form[data-recall]), :has(> form.recall.post), :has(> form.recall.postRemote)', function (event)
  {
    
    var form = event.target;

    if (j$(form).is('[data-recall~="postRemote"], .postRemote'))
    {
      return recallPost(form, 'postRemote');
    }
    else
    {
      return recallPost(form, 'post');    
    }
  });

  
  setTimeout(function()
  {
    recallAutoloadVisible();
  }, 100);

  j$(document).on('click', 'body', function()
  {
    recallAutoloadVisible();
  });

  j$(window).on('resize scroll', function()
  {
    if (recallAutoloadCooldown == true) return;

    recallAutoloadCooldown = true;

    setTimeout(function()
    {
      recallAutoloadCooldown = false;
    }, 400);

    recallAutoloadVisible();
  });
});

function recallAutoloadVisible()
{
  var elements = j$('.deferred, :not(.recallBusy) > [data-recall-accept~="autoload"], :not(.recallBusy) > [data-recall-accept~="autoloadRemote"]');

  // Return immediately if there aren't any matching elements
  if (elements.length === 0) return;

  elements.each(function()
  {
    // Check visibility of each element including its parents and see if the element is actually in the client's view window
    if (j$(this).is(':visible') && (this.getBoundingClientRect().top <= window.innerHeight * 1.1))
    {
      if (j$(this).is('.deferred') && j$(this)[0]?.id)
      {
        j$(this).removeClass('deferred');

        let event = new CustomEvent(j$(this)[0].id);
        event.action = 'load';
        window.dispatchEvent(event);
      }
      else if (j$(this).is('[data-recall-accept~="autoloadRemote"]'))
      {
        recallDoCall(this, 'autoloadRemote');
      }
      else
      {
        recallDoCall(this, 'autoload');   
      }
    }
  });
}

function recallPost(form, trigger, recallPoint)
{
  if (! trigger || trigger == '')
  {
    var trigger = 'post';
    
    if (j$(form).is('[data-recall~="postRemote"], .postRemote'))
    {
      trigger = 'postRemote';
    }
  }
  
  return recallDoCall(form, trigger, recallPoint);
}

function recallFindAnchor(node, trigger)
{
  
  return recallFindRecallPoint(node, trigger);
}

function recallFindRecallPoint(node, trigger)
{
  var recallPoint;

  if (j$(node).attr('data-recall-target'))
  {
    var selector = j$(node).attr('data-recall-target');
    var n = j$(selector)[0];
    
    if (n)
    {
      // Search for anchor relative to the specified target
      return recallFindRecallPoint(n, trigger);
    }
  }

  if (! recallPoint && j$(node).is('[data-recall-accept~="' + trigger + '"]'))
  {
    recallPoint = node;
  }
  
  if (! recallPoint)
  {
    
    recallPoint = j$(node).parents().addBack().find('> [data-recall-accept~="' + trigger + '"]')[0];
  }

  if (! recallPoint && trigger.match('Remote'))
  {
    
    trigger = trigger.replace('Remote', '');
    return recallFindRecallPoint(node, trigger);
  }

  return recallPoint;
}

function recallDoCall(node, trigger, recallPoint)
{
  var remote = false;
  var formData;
  
  if (! recallPoint || recallPoint == '')
  {
    recallPoint = recallFindRecallPoint(node, trigger);
  }
  
  if (! recallPoint)
  {
    return true;
  }
  
  // Check if remote is wanted and supported by recallPoint
  if (trigger.match('Remote') && j$(recallPoint).is('[data-recall-accept~="' + trigger + '"]'))
  {
    // Is remote trigger wanted and supported ?
    remote = true;
    trigger = trigger.replace('Remote', '');
  }
  else
  {
    // Is nonRemote trigger supported ?
    trigger = trigger.replace('Remote', '');

    if (! j$(recallPoint).is('[data-recall-accept~="' + trigger + '"]'))
    {
      // No match between trigger and recallPoint
      return true;
    }
  }
  
  if (remote)
  {
    url = j$(recallPoint).attr('data-recall-remote-url');
  }
  else
  {
    url = j$(recallPoint).attr('data-recall-url');
  }

  if (trigger == 'post')
  {
    formData = new FormData(j$(node)[0]);
    
    var action = j$(node)[0].action;
    action = action.substring(action.indexOf('?')+1).split('&');
    for (var i = 0 ; i < action.length; i++)
    {
      var pair = action[i].split('=');
      formData.append(decodeURIComponent(pair[0]), decodeURIComponent(pair[1]));
    }
  }
  else if (trigger == 'get')
  {
    var href = j$(node)[0].href;
    href = href.substring(href.indexOf('?')+1);
    if (href != '')
    {
      url += '&' + href;
    }
  }

  var target;

  var selector = j$(node).attr('data-recall-replace');
  if (selector)
  {
    target = j$(selector)[0];
  }

  if (! target)
  {
    target = j$(recallPoint).parent();
  }

  j$(target).addClass('recallBusy');

  j$.ajax(
  {
    type: 'POST',
    url: url,
    data: formData,
    processData: false,
    contentType: false,
    success: function(data)
    {
      j$(target).replaceWith(data);

      if (j$(node).attr('data-recall-success-callback'))
      {
        eval(j$(node).attr('data-recall-success-callback'));
      }

      return false;
    }
  });

  if (j$(node).attr('data-recall-callback'))
  {
    eval(j$(node).attr('data-recall-callback'));
  }

  return false;
}


function changeFontSize () {
  var zoom = readCookie('1pageZoom');

  switch(zoom) {
    case 'normal':
      document.body.className = 'mediumZoom';
      // addClassName ('mediumZoom', document.body);
      createCookie('1pageZoom','medium',365);
      break;
    case 'medium':
      document.body.className = 'largeZoom';
      // addClassName ('largeZoom', document.body);
      createCookie('1pageZoom','large',365);
      break;
    case 'large':
      document.body.className = 'normalZoom';
      // addClassName ('normalZoom', document.body);
      createCookie('1pageZoom','normal',365);
      break;
    default:
      document.body.className = 'mediumZoom';
      // addClassName ('mediumZoom', document.body);
      createCookie('1pageZoom','medium',365);
  }

  /* -------------------------------- */

  function addClassName (name, obj) {
    var className = obj.className;

    className = className.replace(/\s*?(.*?)Zoom/g, ''); 
    obj.className = className != '' ? ' ' + className + name : name;
    
  }
  
  function createCookie(name,value,days) {
    var date, expires;

    if (days) {
      date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      expires = "; expires="+date.toGMTString();
    } else expires = "";
    document.cookie = name + "=" + escape(value) + expires + "; path=/";
    // alert(name + "=" + escape(value) + expires + "; path=/");
  }

  function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');

    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }

  function eraseCookie(name) {
    createCookie(name,"",-1);
  }
}


j$( function() {


  j$( 'body' ).removeClass( 'JS-OFF' );
  j$( 'body' ).addClass( 'JS-ON' );
       
  j$( "header .menuBtn button" ).click( function( e ) {
    j$( 'body' ).toggleClass( 'menu-open' );
  });
  
  j$( 'main:has(.standardText .leadart)' ).addClass("hasLeadart");


  if ( document.documentMode) {
    j$( 'body' ).addClass( 'ie-mode' );
  }
  
  var el = document.getElementById('oldBrowser');
  if ( typeof el.style.grid === 'string') {
    j$( 'body' ).addClass( 'gridSupport' );
  } else {
    j$( 'body' ).addClass( 'no-gridSupport' );
  }



  j$( window ).scroll( function() {
    if (j$( window ).scrollTop() > 100) {
      j$('#goTop').fadeIn();
    } else {
      j$('#goTop').fadeOut();
    }
  });

  j$( '#goTop a' ).click( function(e) {
    j$('body').animate({
      scrollTop: 0
    }, 1500);
  console.log( 'test' );
    return false;
  });



  var firstNieuwsH3=j$('.mod_archief1 .so_nieuws .content li:first-of-type .textWrapper h3');
  if ( firstNieuwsH3 ) {
    firstNieuwsH3.replaceWith('<h2>' + firstNieuwsH3.html() +'</h2>');
  }
  j$('.mod_archief1 .content li:first-of-type .imageWrapper .label ').removeAttr( 'style' ).appendTo(j$('.so_nieuws .content li:first-of-type .textWrapper'));


  j$('main section:visible:last').addClass('last-visible');


  j$('.block .text-item blockquote').parent().addClass('hasBlockquote');


  j$('.overview.template-wiwSmartDelta').parent().addClass('wiwOverview').find('h2 a').addClass('nolink').removeAttr( 'href' );



  var leadArt = j$('.standardText').find( '.leadart' );
  if ( leadArt.length !== 0 ) {
    if ( leadArt.next().hasClass( 'block' ) ) {
      j$('.standardText').addClass( 'has-lead-follow-block' );
    }  
  }
  

});




   /*! jsMorph v0.5.0 http://jsMorph.com/ | http://jsMorph.com/license */var jsMorph=function(g,a,e,f,k,j,c){var i=!document.getElementsByClassName,l=(function(C,r,o,K,y,x){var q={},E,N,O,p=C.style,D,t,B,A=0,J,M,L=[],s,I,v=function(m){return[m.offsetWidth,m.offsetHeight,m.offsetLeft,m.offsetTop]},u=function(){if(document.body.currentStyle){return function(m,n){return m.currentStyle[n.replace(/\-(\w)/g,function(){return arguments[1].toUpperCase()})]}}else{return function(m,n){return document.defaultView.getComputedStyle(m,null).getPropertyValue(n)}}}(),H=function(R){var P={},S,m=R.style,Q=document.createElement("div"),n=Q.style;n.cssText="position:absolute;left:0;top:-10ex;width:10em;height:72pt;";R.appendChild(Q);S=v(Q).concat(v(R));P={em:S[0]/10,pt:S[1]/72,pc:S[1]/6,"in":S[1],cm:S[1]/2.54,mm:S[1]/25.4,ex:Math.abs(S[3])/10,"%font":S[0]/1000,"%line":S[0]/1000};n.cssText+=";font-size:"+r["font-size"]+(r["font-family"]?";font-family:"+r["font-family"]:"")+";";S=v(Q);R.removeChild(Q);P.exn=Math.abs(S[3]/10);t=m.cssText;m.cssText+=";position:absolute;left:0%;top:0%;";S=v(R);m.cssText+=";left:-100%;top:-100%;";S=S.concat(v(R));m.cssText=t;P["%outX"]=(S[2]-S[6])/100;P["%outY"]=(S[3]-S[7])/100;return P},w=function(m,Q,P){if(m[2]!="px"&&m[2]!=""){if(m[2]!="%"){m[1]*=P[m[2]]}else{if(!Q.match(/^(font)/)){m[1]*=Q.match(/width|left|right|padding|margin|text-ind/)?P["%outX"]:P["%outY"]}else{m[1]*=P["%"+Q.split("-")[0]]}}}},z=function(m){var n=m.split("#");if(n[1]){n=n[1].split("");n=n.length<6?(n[0]+n[0]+n[1]+n[1]+n[2]+n[2]).split(""):n;return[parseInt(n[0]+n[1],16),parseInt(n[2]+n[3],16),parseInt(n[4]+n[5],16)]}else{return/rgb\((.*)\)/.exec(n[0])[1].replace(/\s*/g,"").split(",")}};C.initStyle=C.style.cssText;if(r["font-size"]){D=/([\-0-9\.]+)([a-z%]+)(!*)/.exec(r["font-size"])}for(var F in r){s=F.match(/opacity/);I=F.match(/color/);if(!(F.replace(/\-(\w)/g,function(){return arguments[1].toUpperCase()}) in p)&&!s){delete (r[F]);continue}O=/([\-0-9\.]+)([a-z%]*)(\s*~*)/.exec(r[F])||[];r[F]=r[F].toString().replace("~","");if(i&&s){N=/\opacity=([0-9]+)\)/.exec(u(C,"filter"));N=["",N==null?100:N[1],""];O=["",O[1]*=100,""];r[F]=O[1]+")"}else{if(I){N=z(u(C,F=="border-color"?"border-left-color":F));O=z(r[F])}else{N=/([\-0-9\.]+)(\D*)/.exec(u(C,F.match(/^(padding|margin)$/)?F+"-left":F.match(/^(border-width)$/)?"border-left-width":F.match(/(border-radius)$/)?(B=(F.match(/^(\-\w+\-)/)||["",""])[1])+"border-"+(B=="-moz-"?"radius-topleft":"top-left-radius"):F))||["0px",0,"px"]}}if(!N[1]&&F.match(/^(height|width)/)){p.zoom=1;L[0]=/([\-0-9\.]+)([a-z%]*)/.exec(u(C,"padding-"+(F=="width"?"left":"top")));L[1]=/([\-0-9\.]+)([a-z%]*)/.exec(u(C,"padding-"+(F=="width"?"right":"bottom")));if((L[0]&&L[0][2]!="px")||(L[1]&&L[1][2]!="px")){w(L[0],"padding",E||(E=H(C)));w(L[1],"padding",E)}N=["",(F=="width"?C.clientWidth:C.clientHeight)-L[0][F=="width"?0:1]-L[1][F=="width"?0:1],"px"]}if(O[3]&&!I){if(O[2]&&O[2]!="px"){E=E||H(C);O[1]=+O[1]+(+N[1])/E[O[2]]}else{O[1]=+O[1]+(+N[1])}r[F]=O[1]+O[2]}if(((N[2]&&N[2]!="px")||(N[2]!=O[2]))&&!I){w(N,F,E||(E=H(C)));w(O,F,E);if(D&&F!="font-size"){if(O[2]=="em"){O[1]*=D[1]/(D[2]!="em"?E.em:1)}if(O[2]=="ex"){O[1]*=E.exn/E.ex}}}if(I){J=[];for(var G=N.length;G--;){J[G]=O[G]-N[G];if(A<J[G]){A=J[G]}}q[F]={full:N,delta:J}}else{N[1]=parseFloat(N[1]);J=parseFloat(O[1])-N[1];if(A<Math.abs(J)){A=J*(s&&!i?100:1)}q[F]={pre:(i&&s?"filter:alpha(opacity=":F+":"),full:N[1],delta:J,unit:O[2]==""?(i&&s?")":""):"px"}}}A=12+Math.abs(o/A*(!K&&K!=0?1:K));if(x.speed&&A>x.speed){}else{x.speed=A}q.speed=A;if(y){y(q,E)}return q}),b=function(m){if(!m){return new Date().getTime()-b.sT||0}else{b.sT=new Date().getTime();return 0}},d=function(t,x,F,y,G,v,s,u){var E,D,p=false,H,z,w,I,r,q,J;for(var C=G.length;C--;){H=G[C];I=H.params;r=H.prop;q=H.initProp;z=t-(H.newTime||0)-I.delay;if(v&&!v[C]&&!H.newTime){continue}E="";if(z>0){w=(F||H.obj.backwards);D=H.ease(z/I.duration);if(z<I.duration){p=true;H.done=null;for(var B in r){if(B.indexOf('color')!=-1){J=[];for(var A=q[B].full.length;A--;){J[A]=q[B].delta[A]?Math.round(+q[B].full[A]+(!w?D:1-D)*q[B].delta[A]):q[B].full[A]}E+=";"+B+":rgb("+J+")"}else{J=(!w?D:1-D)*q[B].delta;if(u){J=Math.round(J)}E+=";"+q[B].pre+(q[B].full+J)+q[B].unit}}H.objStyle.cssText+=E}else{if(!H.done){if(I.doEnd){if(!w){for(var B in r){E+=";"+q[B].pre+r[B]}H.objStyle.cssText+=E}else{H.objStyle.cssText=H.obj.initStyle}}else{for(var B in r){E+=";"+q[B].pre+(q[B].full+(!w?q[B].delta:0))+q[B].unit}H.objStyle.cssText+=E}if(H.onMorphEnd){H.onMorphEnd(H.obj,x(),y,q.speed,s.speed,H.objStyle.cssText)}H.done=true;H.newTime=null}}if(H.onMorph){H.onMorph(H.obj,H.objStyle,t,y+1,q.speed,s.speed,D,H.objStyle.cssText)}}else{p=true}}if(p){s.timer=window.setTimeout(function(){d(x(),x,F,++y,G,v,s,u)},s.speed)}else{s.timer=null;if(C<=0&&s.onMorphEnd){s.onMorphEnd(v,x(),y,s.speed)}}},h=[];this.reset=function(u,o,s,t,w,v,p){for(var q=h.length;q--;){for(var r in h[q]){r=null}h[q]=null;h.pop()}if(u){this.concat(u,o,s,t,w,v,p)}return this};this.init=function(s){var r=h.length,q,p;for(var t=s?r-1:0,o=r;t<o;t++){if(h[t].obj.initStyle!=undefined&&s==undefined){q=h[t].obj.style;p=q.cssText;if(h[t].obj.initStyle!=p){q.cssText=h[t].obj.initStyle}else{p=null}}h[t]["initProp"]=l(h[t].obj,h[t].prop,h[t].params.duration,h[t].params.speed,h[t].onMorphInit,this);if(p&&s==undefined){q.cssText=p}}return this};this.concat=function(p,u,s,r,o,q,m){if(!p.pop&&!p.item){p=[p]}if(!s){s={}}for(var t=p.length;t--;){if(typeof p[t]=="string"){p[t]=document.getElementById(p[t])}h[h.length]={obj:p[t],objStyle:p[t].style,prop:u,params:{duration:s.duration||500,delay:s.delay||0,speed:s.speed!=undefined?s.speed:1,doEnd:s.doEnd!=undefined?s.doEnd:true},ease:r||function(v){return v},onMorphInit:o,onMorph:q,onMorphEnd:m};this.init(true)}return this};if(g){this.concat(g,a,e,f,k,j,c)}this.stop=function(m){window.clearTimeout(this.timer)};this.start=function(q){var p=b();if(q&&(q.pop||q.item)){arguments=q}for(var r=[],s=arguments.length;s--;){for(var o=h.length;o--;){if(h[o].obj==arguments[s]){h[o].newTime=this.timer?p:0.1;r[o]=true}}}window.clearTimeout(this.timer);d(this.timer?p:b(true),b,this.backwards,1,h,r.length?r:null,this,i);return this}};


var easePack = { // see it as black boxes ;o)... you don't need to read or understand this
	quadraticEaseIn : function(n) {return n*n},
	quadraticEaseOut : function(n) {return -n*(n-2)},
	quadraticEaseInOut : function(n) {if ((n*=2)<1) return 0.5*n*n; return -0.5*(--n*(n-2)-1)},
	
	cubicEaseIn : function(n) {return n*n*n},
	cubicEaseOut : function(n) {return --n*n*n+1},
	cubicEaseInOut : function(n) {if ((n*=2)<1) return 0.5*n*n*n; return 0.5*((n-=2)*n*n+2)},
	
	quarticEaseIn : function(n) {return n*n*n*n},
	quarticEaseOut : function(n) {return -(--n*n*n*n-1)},
	quarticEaseInOut : function(n) {if ((n*=2)<1) return 0.5*n*n*n*n; return -0.5*((n-=2)*n*n*n-2)},
	
	quinticEaseIn : function(n) {return n*n*n*n*n},
	quinticEaseOut : function(n) {return (n=n-1)*n*n*n*n+1},
	quinticEaseInOut : function(n) {if ((n*=2)<1) return 0.5*n*n*n*n*n; return 0.5*((n-=2)*n*n*n*n+2)},
	
	sinusoidalEaseIn : function(n) {return -Math.cos(n*Math.PI/2)+1},
	sinusoidalEaseOut : function(n) {return Math.sin(n*Math.PI/2)},
	sinusoidalEaseInOut : function(n) {return -0.5*(Math.cos(Math.PI*n)-1)},
	
	exponentialEaseIn : function(n) {return n==0 ? 0 : Math.pow(2, 10*(n-1))},
	exponentialEaseOut : function(n) {return n==1 ? 1 : -Math.pow(2, -10*n)+1},
	exponentialEaseInOut : function(n) {if (n==0) return 0; if (n==1) return 1; if ((n*=2)<1) return 0.5*Math.pow(2, 10*(n-1)); return 0.5*(-Math.pow(2, -10*(n-1))+2)},
	
	circularEaseIn : function(n) {return -(Math.sqrt(1-n*n)-1)},
	circularEaseOut : function(n) {return Math.sqrt(1- --n*n)},
	circularEaseInOut : function(n) {if ((n/=0.5)<1) return -0.5*(Math.sqrt(1-n*n)-1); return 0.5*(Math.sqrt(1-(n-=2)*n)+1)},
	
	elasticEaseIn : function(n) {var s, a=0.1, p=0.4; if (n==0) return 0; if (n==1) return 1; if (!p) p=0.3; if (!a||a<1) {a=1; s=p/4} else s=p/(2*Math.PI)*Math.asin(1/a); return -(a*Math.pow(2, 10*(n-=1))*Math.sin((n-s)*(2*Math.PI)/p))},
	elasticEaseOut : function(n) {var s, a=0.1, p=0.4;	if (n==0) return 0; if (n==1) return 1; if (!p) p=0.3; if (!a||a<1) {a=1; s=p/4} else s=p/(2*Math.PI)*Math.asin(1/a); return (a*Math.pow(2, -10*n)*Math.sin((n-s)*(2*Math.PI)/p)+1)},
	elasticEaseInOut : function(n) {var s, a=0.1, p=0.4; if (n==0) return 0; if (n==1) return 1; if (!p) p=0.3; if (!a||a<1) {a=1; s=p/4} else s=p/(2*Math.PI)*Math.asin(1/a); if ((n*=2)<1) return -0.5*(a*Math.pow(2, 10*(n-=1))*Math.sin((n-s)*(2*Math.PI)/p)); return a*Math.pow(2, -10*(n-=1))*Math.sin((n-s)*(2*Math.PI)/p)*0.5+1},
	
	backEaseIn : function(n) {var s=1.70158; return n*n*((s+1)*n-s)},
	backEaseOut : function(n) {var s=1.70158; return (n=n-1)*n*((s+1)*n+s)+1},
	backEaseInOut : function(n) {var s=1.70158*1.525; if ((n*=2)<1) return 0.5*(n*n*((s+1)*n-s)); return 0.5*((n-=2)*n*((s+1)*n+s)+2)},
	
	bounceEaseIn : function(n) {return 1-bounceEaseOut(1-n)},
	bounceEaseOut : function(n) {if ((n/=1)<(1/2.75)) return 7.5625*n*n; else if (n<(2/2.75)) return 7.5625*(n-=(1.5/2.75))*n+0.75; else if (n<(2.5/2.75)) return 7.5625*(n-=(2.25/2.75))*n+0.9375; else return 7.5625*(n-=(2.625/2.75))*n+0.984375},
	bounceEaseInOut : function(n) {if (n<0.5) return bounceEaseIn(n*2)*0.5; return bounceEaseOut(n*2-1)*0.5+0.5}
};


function imgSlider(obj, content, options) {



  var slider = document.getElementById(obj) || obj,
      imgs = slider.getElementsByTagName('img'),
      myMorph = new jsMorph(),
      bullets, bullet;

  if (content.length <= 1) return;  // don't do anything else if only one image
  slider.current = 0;
  slider.done = true;
  if (!options) options = {};
  
  bullets = slider.parentNode.appendChild(document.createElement('div')); // draw bullet wrapper
  bullets.className = 'bullets';
  
  for(var n = 0, m = content.length; n < m; n++) { // draw bullets
    bullet = bullets.appendChild(document.createElement('div'));
    if (!n) bullet.className = 'selected';
    bullet.me = n; // for later order recognition
  }
  
  
  bullets.onclick = function(e) { // event delegation for bullet click
    var  e = e || window.event, obj = e.target || e.srcElement;

    if (!slider.done || obj.me == undefined) return;
    setInterval(); // also clears interval... do something about mouseover...
    doMorph(options.mode, obj.me);
  }

  j$("div.prevNextBtns>span").click( function(e) { // event delegation for next/prev click
    var obj = e.target; 
    var next = false;
    
    if ( j$( obj ).hasClass('next') || j$( obj ).parent().hasClass('next')) {
      next = true; 
    }
    doMorph(options.mode,undefined,!next);
  });


if ( j$("div.prevNextBtns>span").length > 0) {

  var xDown = null,yDown = null;

  j$("#"+obj).on( "touchstart", function(e) {
    xDown = e.originalEvent.touches[0].clientX;
    yDown = e.originalEvent.touches[0].clientY;
  });
 
  j$("#"+obj).on( "touchmove", function(e) {
  
    if ( ! xDown || ! yDown ) {
        return;
    }

    var xUp = e.originalEvent.touches[0].clientX;
    var yUp = e.originalEvent.touches[0].clientY;

    var xDiff = xDown - xUp;
    var yDiff = yDown - yUp;

    if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) { 
      if ( xDiff > 0 ) {
        
        doMorph(options.mode,undefined,false);
      } else {
        
        doMorph(options.mode,undefined,true);
      }
    } else {
       
    }
    
    
    xDown = null;
    yDown = null;
    
  });

}

  slider.appendChild(slider.children[0].cloneNode(true)); // clone is now on top in DOM


  // for (var n = imgs.length; n--;) imgs[n].onload = function(){myMorph.start()}
  
  if (options.autoStart || options.autoStart == undefined) setInterval(); // finally,... get it going
  
  if (options.hoverStop) { // stop/start auto rotate on hover
    (options.hoverStop == 'bullets' ? bullets : slider).onmouseover = clearInterval;
    (options.hoverStop == 'bullets' ? bullets : slider).onmouseout = setInterval;
  }
  
  function setInterval () {
    clearInterval();
    slider.interval = window.setInterval(function() {
      doMorph(options.mode);
    }, options.interval || 6000);
  }

  function clearInterval () {
    window.clearInterval(slider.interval);
  }

  function doMorph (mode, no, backwards) {
    bullets.children[slider.current].className = '';

    if ( no != undefined ) {
      slider.current = no;
    } else {
        slider.current = backwards ? slider.current-1 : slider.current+1;
        //out of bounds
        if (slider.current >= content.length) slider.current = 0;
        if (slider.current < 0) slider.current = content.length-1;
     }

    bullets.children[slider.current].className = 'selected';

    slider.children[0].innerHTML = content[slider.current][0].replace(/%3C/g, '<');

    if (typeof j$ != 'undefined')
    {
      j$('a[rel="external"]').attr('target', '_blank');
    }
    else if (typeof $$ != 'undefined')
    {
      $$('a').each(function (link)
      {
        if (link.rel == 'external')
        {
          link.target = '_blank';

          if (link.title == '')
          {
            link.title = 'Opent in een nieuw venster';
          }
        }
      });
    }
 
    if ((typeof textShadowOption != 'undefined') && (j$))
    {
      
      j$("h2.slideTitle").textShadow(textShadowOption);
    }

    slider.done = false;
    
    switch(mode){
      case 'LEFTRIGHT':
        // do something
        break;
      default: // case null || undefined || 'CROSSFADE'
        myMorph.reset(slider.children[1],
          {opacity:0},
          {duration: options.duration || 1000},
          options.ease ? easePack[options.ease] || function(n) {return --n*n*n+1} : null,
          null,
          null,
          function(){slider.appendChild(slider.children[0]); slider.children[0].style.cssText = ''; slider.done = true;}
        ).start(); // done with img.onlad...
    }
    
    /*
    if (!mode || mode == 'CROSSFADE') myMorph.reset(slider.children[1],
      {opacity:0},
      {duration: options.duration || 1000},
      options.ease ? easePack[options.ease] || function(n) {return --n*n*n+1} : null,
      null,
      null,
      function(){slider.appendChild(slider.children[0]); slider.children[0].style.cssText = ''; slider.done = true;}
    ).start();
    else ; // more modes */
  }
};


       