jQuery(document).ready(function() {
    var animatieduration = 6000;
    var animatiefadetime = 2000;
    var animatieactive_image = -1;
    var animatieimgcount = 0;
    
    animatieimgcount = jQuery('.fader').size();
    if (animatieimgcount == 1)
        jQuery('.fader').fadeIn(animatiefadetime);
    else
        cycleFotos();

    function headeranimatie($index)
    {
        setTimeout(function(){ $('.fader:eq('+$index+') .animatie-image-tekst').animate({"bottom":"0px"},500); },1000);
        setTimeout(function(){ $('.fader:eq('+$index+') .animatie-image-tekst').animate({"bottom":"-40px"},500); },5500);
        
        $('.fader:eq('+$index+') .animatie-image-left-container').animate({"width":"400px"},5000);    
        $('.fader:eq('+$index+') .animatie-image-left').animate({"left":"0px"},5000);    
        $('.fader:eq('+$index+') .animatie-image-right').animate({"top":"-120px"},5000);  
        
  
        
        setTimeout(function(){
            
            $('.fader:eq('+$index+') .wittemarkeer1').animate({"opacity":"toggle","left":"100px"},2500,function(){
                $('.fader:eq('+$index+') .wittemarkeer1').animate({"opacity":"toggle","left":"0px"},2500);        
            });  
            
            $('.fader:eq('+$index+') .wittemarkeer2').animate({"opacity":"toggle","left":"475px"},2500,function(){
                $('.fader:eq('+$index+') .wittemarkeer2').animate({"opacity":"toggle","left":"450px"},2500);        
            });    
            $('.fader:eq('+$index+') .wittemarkeer3').animate({"left":"385px"},2000);       
        },1000)
     
    }

    function headeranimatiereset($index){
        $('.fader:eq('+$index+') .animatie-image-tekst').css({"bottom":"-50px"});
        $('.fader:eq('+$index+') .animatie-image-left-container').css({"width":"330px"});    
        $('.fader:eq('+$index+') .animatie-image-left').css({"left":"-100px"});    
        $('.fader:eq('+$index+') .animatie-image-right').css({"top":"0px"});
        $('.fader:eq('+$index+') .wittemarkeer1').css({"opacity":"toggle","left":"200px","display":"none"});
        $('.fader:eq('+$index+') .wittemarkeer2').css({"opacity":"toggle","left":"500px","display":"none"});    
        $('.fader:eq('+$index+') .wittemarkeer3').css({"left":"315px"}); 
    }
    
    function cycleFotos()
    {
        var prev = animatieactive_image;
        var next = animatieactive_image+1;    
        
        if(next == animatieimgcount)
        {
            next = 0;
        }                
        
        if(prev > -1)
        {
            jQuery('.fader:eq('+prev+')').fadeOut(animatiefadetime);                
            jQuery('.fader:eq('+prev+') .animatie-image-left').fadeOut(animatiefadetime);
            jQuery('.fader:eq('+prev+') .animatie-image-right').fadeOut(animatiefadetime);
        }

        jQuery('.fader:eq('+next+')').fadeIn(animatiefadetime);                
        jQuery('.fader:eq('+next+') .animatie-image-left').fadeIn(animatiefadetime);                
        jQuery('.fader:eq('+next+') .animatie-image-right').fadeIn(animatiefadetime);                
        
        animatieactive_image = next;        
        headeranimatie(animatieactive_image);
        setTimeout(function(){ headeranimatiereset(prev)},animatiefadetime);                
        setTimeout(cycleFotos,animatieduration);
    }            
});


