$(document).ready(function() {
    $('.weetjes ul').rotate({ timeout: 8000, randomise: true });
});

/**
* Rotate plugin 
* Rotate children elements, the container takes the height of the highest child element
* @param :  timeout interval, if not given default to 5000ms
* @param :  randomise, start with random item, default false
*/

(function($) {
    jQuery.fn.rotate = function(options) {

        settings = jQuery.extend({
            timeout: 5000,
            randomise: false
        }, options);

        return this.each(function() {

            var $container = $(this);
            var $items = $(this).children();
            var timer;
            var current = 0;
            var H = 0;

            function showNext() {

                next = current + 1;
                if (next >= $items.size()) next = 0;
                $($items[current]).fadeOut(200);
                $($items[next]).delay(300).fadeIn(200);

                current = next;

            };

            // randomise
            if (settings.randomise) {
                var randomNr = Math.ceil($items.size() * Math.random());
                current = randomNr - 1;
            }

            // geef de container de hoogte van de hoogste tekst
            $items.each(function(i) {
                (i == current) ? $(this).show() : $(this).hide();
                if ($(this).height() > H) {
                    H = $(this).height();
                }
            });
            $container.css({ 'height': H + 'px' });
            // start loop
            timer = setInterval(function() { showNext(); }, settings.timeout);

        });

    };
})(jQuery);


/**
* Delay plugin inspired by learningjquery.com/2007/01/effect-delay-trick
* @author : Jp Siffert
* @param :  delay interval, if not given default to 1000ms
* @return : jquery chain object
*/
$.fn.delay = function(delay) {
    if (typeof delay === "undefined") delay = 1000;
    return this.animate({ 'void': 0 }, delay);
}