var duration_highlight  = 2000;
var duration2_highlight = 500;
var still_highlight     = 7000;
var active_highlight    = 0;
var next_highlight      = 1;
var previous_highlight  = 0;
var aantalnb_highlight  = 0;
var pauze_highlight     = false;
var timeoutcallback_highlight;

jQuery(function(){
    
    aantalnb_highlight = jQuery('.hightlight-fader').size();
    
    // begin intro laten zien
    jQuery(".hightlight-item:eq(0)").css('background-color','#3C8ADB');
    jQuery('.hightlight-fader:eq(0)').fadeIn();
    jQuery('.hightlight-comments:eq(0)').css('z-index','1');
    jQuery('.hightlight-comments:eq(0)').stop().animate({"left":"0px"},500,"swing");
    
    // onlick actie
    jQuery('.hightlight-item').click(function(){
        var index_highlight = jQuery(".hightlight-item").index(this);    
        shownieuwsatindex_highlight (index_highlight);
        return false;
    });
    
    timeoutcallback_highlight = setTimeout(autoscrollnieuws_highlight,still_highlight);
    
    // pauze 
    jQuery("#highlight-header").hover(function(){
        pauze_highlight = true;
        jQuery('#highlight-header-pauze').fadeIn();
    },function(){
        pauze_highlight = false;
        jQuery('#highlight-header-pauze').fadeOut();    
    });
});

function autoscrollnieuws_highlight()
{
    shownieuwsatindex_highlight(next_highlight);    
}

function shownieuwsatindex_highlight (index_highlight)
{
    clearTimeout(timeoutcallback_highlight);
    if(!pauze_highlight)
    {
        previous_highlight = active_highlight;
        
        if((index_highlight+1) == aantalnb_highlight)
        {
            next_highlight = 0;
        }
        else
        {
            next_highlight = index_highlight + 1;
        }
        
        jQuery('.hightlight-item:eq('+previous_highlight+')').css('background-color','#E9E9E9');                    
        jQuery('.hightlight-item:eq('+index_highlight+')').css('background-color','#3C8ADB');
        
        jQuery('.hightlight-comments').css('z-index','0');                    
        jQuery('.hightlight-comments:eq('+index_highlight+')').css('z-index','1');
        jQuery('.hightlight-comments').stop().animate({"left":"-260px"},500,"swing");
        
        setTimeout( function(){ jQuery('.hightlight-comments:eq('+index_highlight+')').stop().animate({"left":"0px"},500,"swing"); }, 500);
        
        setTimeout( function(){ jQuery('.hightlight-fader:eq('+previous_highlight+')').fadeOut(600); }, 200); 
        setTimeout( function(){ jQuery('.hightlight-fader:eq('+index_highlight+')').fadeIn(600); }, 200);
        
        active_highlight = index_highlight;
    }
    
    timeoutcallback_highlight = setTimeout(autoscrollnieuws_highlight,still_highlight);
}

jQuery(function(){
    //instellingen aanpasbaar
    var automatisch             = 1; // 1=aan / 0=uit
    var beginnenbij             = 0; //beginnen bij
    var hoelangstilstaan        = 5000; // 1000 = 1sec
    var schuifknopcss           = new Array("color","#245DB2","#666"); // css, active, nonactive
    var commentaarinbeeld       = "5px"; // positie binnnen balk
    var commentaarbuitenbeeld   = "75px"; // positie buiten balk
    var resetpositie            = "0px"; // blok left positie bij reset/begin

    //instellingen niet aanpasbaar
    var totaal      = jQuery(".schuifblok").size();
    var breed       = jQuery(".schuifblok").width();
    var comheight   = jQuery(".schuifblokcommentaar").height();
    var pauze       = false;
    var huidig      = beginnenbij;
    var timeoutcallback; 

    //start schuiven
    jQuery('.schuifblok:eq('+beginnenbij+')').css("left","0px");
    jQuery('.schuifblokcommentaar:eq('+beginnenbij+')').animate({"top":commentaarinbeeld});
    schuivenactiveknop(huidig);
    
    if (totaal > 1)
        timeoutcallback = setTimeout(autoschuiven,hoelangstilstaan);

    function schuivenactiveknop($positie)
    {
       /* jQuery('.schuifnaarpositie').css(schuifknopcss[0],schuifknopcss[2]);
        jQuery('.schuifnaarpositie:eq('+$positie+')').css(schuifknopcss[0],schuifknopcss[1]);*/
    }
    
    function schuifcommentaar($huidig,$positie){
        jQuery('.schuifblokcommentaar:eq('+$huidig+')').animate({"top":commentaarbuitenbeeld},function(){
            jQuery('.schuifblokcommentaar:eq('+$huidig+')').css("top","-"+comheight+"px");    
        });
        jQuery('.schuifblokcommentaar:eq('+$positie+')').animate({"top":commentaarinbeeld});    

    }

    jQuery("#schuifblokcontainer").hover(function(){
        pauze = true;
        jQuery('#schuifblokpauze').fadeIn();
    },function(){
        pauze = false;   
        jQuery('#schuifblokpauze').fadeOut();  
    });
    
    function autoschuiven()
    {
        if(automatisch==1)
        {
            if(huidig < (totaal-1))
            {
                positie = huidig + 1;
                schuiven(positie);
            } 
            else if(huidig == (totaal-1))
            {
                doorgaannaeinde();
                setTimeout(function() { schuiven(positie); },hoelangstilstaan);
            }
        }
    }
    
   /* jQuery('.schuifnaarpositie').click(function()
    {
        positie = jQuery(".schuifnaarpositie").index(this); 
        schuiven(positie);
        return false;
    }); */

    jQuery('.schuifnaarvorige').click(function(){
        if(huidig>0)
        {
            positie = huidig - 1;
            schuiven(positie);
        }
        else
        {
            teruggaanbijbegin();
        }
        return false;
    });
    
    jQuery('.schuifnaarvolgende').click(function(){
        if(huidig < (totaal-1))
        {
            positie = huidig + 1;
            schuiven(positie);
        }
        else
        {
            doorgaannaeinde();
        }
        return false;
    });
    
    function doorgaannaeinde(){
        clearTimeout(timeoutcallback);
        laatste = totaal-1;
        jQuery('.schuifblok:eq(0)').css("left",breed+"px");
        jQuery('.schuifblok:eq('+laatste+')').animate({"left":"-"+breed+"px"});
        jQuery('.schuifblok:eq(0)').animate({"left":resetpositie});
        huidig     = 0;    
        positie = 1;
        schuivenactiveknop(huidig);
        schuifcommentaar(laatste,huidig);
        timeoutcallback = setTimeout(autoschuiven,hoelangstilstaan);
    }

    function teruggaanbijbegin(){
        clearTimeout(timeoutcallback);
        laatste = totaal-1;
        jQuery('.schuifblok:eq('+laatste+')').css("left","-"+breed+"px");
        jQuery('.schuifblok:eq('+laatste+')').animate({"left":resetpositie});
        jQuery('.schuifblok:eq(0)').animate({"left":breed+"px"});
        huidig     = laatste;    
        positie = laatste;
        schuivenactiveknop(positie);
        schuifcommentaar(0,laatste);
        timeoutcallback = setTimeout(autoschuiven,hoelangstilstaan);
    }
    
    function schuiven(positie)
    {
        clearTimeout(timeoutcallback);
        if(!pauze)
        {
            if(positie==huidig){}
            else{
                if(positie>huidig)
                {
                    jQuery('.schuifblok').not('.schuifblok:eq('+huidig+')').css("left",breed+"px");
                    jQuery('.schuifblok:eq('+huidig+')').animate({"left":"-"+breed+"px"});
                    jQuery('.schuifblok:eq('+positie+')').animate({"left":resetpositie});
                    schuivenactiveknop(positie);
                    schuifcommentaar(huidig,positie);
                }
                else
                {
                    jQuery('.schuifblok').not('.schuifblok:eq('+huidig+')').css("left","-"+breed+"px");
                    jQuery('.schuifblok:eq('+huidig+')').animate({"left":breed+"px"});
                    jQuery('.schuifblok:eq('+positie+')').animate({"left":resetpositie});
                    schuivenactiveknop(positie);
                    schuifcommentaar(huidig,positie);
                }
                huidig = positie;
            }
        }
        timeoutcallback = setTimeout(autoschuiven,hoelangstilstaan);
    }
});

$(function(){   
    $('#schuifpijlen-top').click(function(){
        huidigepositie = $('#schuifknoppen-scrollijst').position();
        if(huidigepositie.top < 0)
        {
            $('#schuifknoppen-scrollijst').stop(true,false);
            var scrollamount = huidigepositie.top < -190 ? 190 : (0-huidigepositie.top);
            $('#schuifknoppen-scrollijst').animate({'top':'+='+scrollamount},500);
        }
    });

    $('#schuifpijlen-bottom').click(function(){
        huidigepositie = $('#schuifknoppen-scrollijst').position();
        maxpx = 38 * $('.schuifleden').size() / 2;
        if(-huidigepositie.top < maxpx)
        {
            $('#schuifknoppen-scrollijst').stop(true,false).animate({'top':'-=190px'},500);
        }
    });
});

function sendheeftuvragen(id)
{
    if(jQuery('#heeftuvragen_naam').val()=="" || jQuery('#heeftuvragen_naam').val()=="Uw naam..." || jQuery('#heeftuvragen_email').val()=="" || jQuery('#heeftuvragen_email').val()=="Uw email..." || jQuery('#heeftuvragen_bericht').val()=="" || jQuery('#heeftuvragen_bericht').val()=="Uw vraag of opmerking")
    {
        alert('U dient alle velden in te vullen als u het \'Heeft u vragen\' formulier wilt versturen.');
        return false;    
    }
    return true;                                                                                                                                                          
}

function sendbelmijterug(id)
{
    if(jQuery('#belmijterug_naam').val()=="" || jQuery('#belmijterug_naam').val()=="Uw naam..." || jQuery('#belmijterug_telefoon').val()=="" || jQuery('#belmijterug_telefoon').val()=="Uw telefoonnummer...")
    {
        alert('U dient alle velden in te vullen als u het \'Bel mij terug\' formulier wilt versturen.');
        return false;    
    }
    return true;                                                                                                                                                         
}

$(function(){
    FancyBoxInit();
});

function FancyBoxInit()
{
    $('.fancybox, .thickbox').fancybox({
        'titleShow'     : false,
        'transitionIn'  : 'none',
        'transitionOut' : 'none'
    });
}
