$(function () {

    // Call Fancybox for Kluswizard
    $(".kluswizard-link").fancybox({
        'width': 1000,
        'height': 650,
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });

    $(".kluswizard-link").click(function () {
        $("#fancybox-wrap").addClass("kluswizard");
    });



    if ($("#tweet-listing").length) {
        $("#tweet-listing").tweet({
            avatar_size: 24,
            count: 5,
            query: "nldoet",
            loading_text: "zoeken in twitter..."
        }).bind("empty", function () { $(this).append("Geen tweets gevonden"); });
    }

    // Cufon settings

    Cufon.replace('#content-top p, #quote span.author', { fontFamily: 'SaunaItalic', hover: 'true' });
    Cufon.replace('.saunabolditalic, #content-top p.big, #content-top p.big a, #content-header h2, #content-bottom h2, .shortCuts li a', { fontFamily: 'SaunaBoldItalic', hover: 'true' });
    Cufon.replace('#quote h2', { fontFamily: 'SaunaBold', hover: 'true' });
    Cufon.replace('#metamenu li a, #footer-menu li a, #sponsor-logos p, #content-top h4', { fontFamily: 'LubalinGraphBook', hover: 'true' });

    // Set fullsize background based on body id

    if ($("html").hasClass("no-backgroundsize")) {
        var bg = $("#body").attr("class");

        switch (bg) {
            case 'bg1':
            case 'bg2':
                break;
            default:
                bg = "bg1";
                break;
        }

        $.backstretch("/nldoet/images/home/bg2.jpg", { speed: 150 });

        // $.backstretch("/nldoet/images/home/" + bg + ".jpg", { speed: 150 });
    }

    // Quote slider

    var quotes = $("#quote").children(".quote");
    var bullets = $("#bullets").children(".bullet");
    var btnPlay = $("#play").hide();
    var btnPause = $("#pause").hide();
    var int;
    bullets.click(function () {
        pause();
        var clickedBullet = $(this);
        //bullets.removeClass("active");
        //$(this).addClass("active");
        var index = bullets.index(clickedBullet);
        $(".quote:visible").fadeOut("fast", function () {
            showQuote(quotes.eq(index));
        });

    });
    var showQuote = function (quote) {
        quote.fadeIn().map(function () {
            //console.log('id=' + $(this).attr('id'));
            var matchingBullet = bullets.eq(quotes.index(quote));
            bullets.not(matchingBullet).removeClass('active');
            matchingBullet.addClass('active');
        });
    }

    var first = quotes.hide().css("position", "absolute").eq(0);
    showQuote(first);

    var play = function (first) {
        btnPlay.hide(0, function () {
            //btnPause.show();
        });
        return window.setInterval(function () {
            var next = $(".quote:visible").fadeOut().next(".quote");
            if (next.length === 0) {
                next = first;
            }
            showQuote(next);
        }, 4000);
    }
    var pause = function () {
        window.clearInterval(int);
        btnPause.hide(0, function () {
            //btnPlay.show();
        });
    };

    btnPlay.click(function () {
        int = play(first);
    });

    btnPause.click(function () {
        pause();
    });
    int = play(first);
});

