$(function(){
	if($('#facebook-wall').length > 0) $('#facebook-wall').fbWall({ id:'100002451263557',accessToken:'206158599425293|4a16ef57ef4bc8d723df5aa2.1-100002451263557|6ZDlqsIPX255JfLeMHozQjWVe3I',showGuestEntries:false,
        showComments:true,                                             
        max:3,
        timeConversion:24
    });
});


$(document).ready(function(){
    
    // opject voor de pdf viewer    
    if ($("a[rel^='prettyPhoto']").length > 0) {
    
    	$("a[rel^='prettyPhoto']").prettyPhoto();
    }
   
   // animeren van de imagerotator
    
    // begin het eerste plaatje te loaden
    var image_index = 0;
    var total = $('#bg_image_js a').length;
    
    $('.rotator-wrapper.nolink').each(function(){
        
        $(this).css("cursor","auto");        
        $(this).find('.slide-button').css("display","none");
    });

    $('#bg_image_js').each(function(){
        
        if(total > 0){
        
            var image = $('#bg_image_js').children('a')[0];
            
            var imageDOM = "<img src='"+ $(image).attr('href') +"' />";
            
            $(imageDOM).load(function(){
                $('#bg_image_js').css("background",'url(' + $(image).attr('href') + ') no-repeat center center');
                
                if(total > 1) animateImage(1, total);
                
            });
        }
    });
    
    // rotator animeren    
    animateRotator(0,3);
    
    $("#advertentie-rotator-boven, #advertentie-rotator-onder").mouseenter(function() {
        
        $(this).animate({
            opacity: 0.8
          }, 100, function() {
            
          });        
        
      }).mouseleave(function() {
      
        $(this).animate({
            opacity: 1
          }, 100, function() {
            
          });        
      });    
});

function animateImage(index, total){

    var image = $('#bg_image_js').children('a')[index];
    var index = index;
    var imageDOM = "<img src='"+ $(image).attr('href') +"' />";
    
    $(imageDOM).load(function(){
        
        $('#bg_image_js .fade-helper').css("background", $('#bg_image_js').css('background'));
        $('#bg_image_js').css("background",'url(' + $(image).attr('href') + ') no-repeat center center');
        
        $('#bg_image_js .fade-helper').css("opacity",1);
        
        index ++;
        if(index == total) index = 0;
        
          $('#bg_image_js .fade-helper').delay(4000).animate({
            opacity: 0
          }, 2000, function() {
            animateImage(index, total);
          });        
    });
}

var delay = 500;

function animateRotator(index, total){
    
    var total = total;
    var oldindex = index - 1;
    if(oldindex == -1) oldindex = 2
    var index = index;    
    
    $(this).children('.advertentie-slide').css('z-index',0);
    
    $('#advertentie-rotator-boven').each(function(){
        
        $($(this).children('.advertentie-slide')[oldindex]).delay(delay).css('left','0px');
        $($(this).children('.advertentie-slide')[oldindex]).delay(delay).css('z-index',2);
        $($(this).children('.advertentie-slide')[oldindex]).delay(delay).animate({
            
            left: '237px'
            
        }, 500, function() {
            
        });
        
        $($(this).children('.advertentie-slide')[index]).delay(delay).css('z-index',1);
        $($(this).children('.advertentie-slide')[index]).delay(delay).css('left','-237px');
        $($(this).children('.advertentie-slide')[index]).delay(delay).animate({
            
            left: '0px'
            
        }, 500, function() {
            
            index ++;
            
            if(index == 3) index = 0;            
            animateRotator(index,total);
            
        });
    
    });
    
    $('#advertentie-rotator-onder').each(function(){
    
        $($(this).children('.advertentie-slide')[oldindex]).delay(delay).css('left',0);
        $($(this).children('.advertentie-slide')[oldindex]).delay(delay).css('z-index',1);
        $($(this).children('.advertentie-slide')[oldindex]).delay(delay).animate({
            
            left: '-237px'
            
        }, 500, function() {
            
        });
        
        $($(this).children('.advertentie-slide')[index]).delay(delay).css('z-index',2);
        $($(this).children('.advertentie-slide')[index]).delay(delay).css('left','237px');
        $($(this).children('.advertentie-slide')[index]).delay(delay).animate({
            
            left: '0'
            
        }, 500, function() {
            
        });
    });
        
}

// functies van de advertentierotator
function openOranjewekenFolder(){
$.prettyPhoto.open("/oranjeweken.html?iframe=true&width=100%&height=100%");
}


// functies van de advertentierotator
function openWereldwekenFolder(){
$.prettyPhoto.open("/wereldweken.html?iframe=true&width=100%&height=100%");
}


function openZomerAdvertentie(){
$.prettyPhoto.open("/media/afbeeldingen/zomeradvertentie.png");
}

// functies van de advertentierotator
function openActionbanner(){
$.prettyPhoto.open("http://vimeo.com/26594451?width=640&height=360");
}
