// jQuery functies
$(document).ready(function(){

    // Links met rel="external" moeten in een nieuw venster worden geopend
    $('A[rel="external"]').click( function() {
        window.open(jQuery(this).attr('href') );
        return false;
    });

    // Prefill text for inputs
    $('input').example(function() {
        return $(this).attr('title');
    }, {className: 'searchinputtxt'});

    // Edit in place toolbar
    $('#eipToolbar').css({'opacity': "0.9"});

    // Bij alle anker links de pagina url ervoor plakken
    sCurrentUrl = window.location.href;
    var iDashPos = sCurrentUrl.indexOf('#', 0);
    if(iDashPos !== -1){
        sCurrentUrl = sCurrentUrl.substring(0,iDashPos);
    }
    $('div.col2 a[href^="#"]').each(function(){
       $(this).attr('href',sCurrentUrl + $(this).attr('href'));
    });


    // Diashow
    $('.diashow').cycle();

    // Nieuws en aanbiedingen tabset
    $('.wrap-nieuws-aanbiedingen ul a').click(function(e){
        e.preventDefault();

        // in het href attribuut van de links staat de tab die geactiveerd moet worden
        sActivateTab = $(this).attr('href');

        // Het juiste tabje highlighten
        $('.wrap-nieuws-aanbiedingen ul').removeClass('tab-aanbiedingen tab-nieuws');
        $('.wrap-nieuws-aanbiedingen ul').addClass(sActivateTab);

        // De juiste div met content tonen
        $('.wrap-nieuws-aanbiedingen .tab-nieuws, .wrap-nieuws-aanbiedingen .tab-aanbiedingen').hide();
        $('.wrap-nieuws-aanbiedingen .' + sActivateTab).show();
    });

    // "Lees meer" link in aanbiedingen div
    $('.toggle-tab-aanbiedingen').click(function(e){
        e.preventDefault();
        $('.tab-aanbiedingen div').show();
        $(this).hide();
    });

    // "Lees meer" link in nieuws div
    $('.toggle-tab-nieuws').click(function(e){
        e.preventDefault();
        $('.tab-nieuws div').show();
        $(this).hide();
    });

    // Kaart vergroten met behulp van de colorbox plugin
    $(".colorbox").colorbox();


    // De banners mee laten scrollen met de pagina
    iFlowTop = $('#flow').position().top;
    iFlowBottom = $('#flow').height() + iFlowTop;
    iFooterTop = $('#footer').position().top;
    iScrollSpace = Math.floor(iFooterTop - iFlowBottom); // De beschikbare ruimte voor de banners om naar onder verplaatst te worden

    $(window).scroll(function () {
        iScroll = $(window).scrollTop(); // het aantal pixels wat er gescrolled is op de pagina
        if((iFlowTop <= iScroll+40) && ((iScroll+40) < (iScrollSpace))){
            // De banner div omlaag verplaatsen als er gescrolled wordt
           $('#flow').css('margin-top',(iScroll-iFlowTop+40)+'px');
        }
    });


});


// Cufon font replacement
Cufon.replace('.box-contact, a.lev1cufon, #footer .links, #contentWrap .col3 ul.topnav', { fontFamily: 'Univers Condensed'});
Cufon.replace('#contentWrap .col2 h1, #footer .slogan', { fontFamily: 'Eurostile'});
