jQuery(document).ready(function() {
	// Teaser carousel:
	jQuery(".tc").sbo_tc({
		auto: true,				// if true, auto sliding
		startRandom: true,		// if true, starts at random position
		speed: 10000				// change interval in ms.
	});	
});	
		
/* 
 * SBO Word leraar in het VO
 * Teaser Carousel - jQuery Plugin
 * 
 * Dependent on:
 *	- jQuery 1.4+
 * 	- jCarouselLite (http://www.gmarwaha.com/jquery/jcarousellite/#doc)
 */
 (function($) {
    $.fn.sbo_tc = function(options) {
        var defaults = {            
            speed: 5000,
            auto: true,
			startRandom: true
        };

        // Extend our default options with those provided.
        var options = $.extend(defaults, options);

        // Prefetched jQuery objects
        var self = $(this);
		var $teasers = $("li.teaser", self);

        // timer
        var timer;        		   

        var teaserCarousel = jQuery('.tc').jCarouselLite({
            btnNext: "#ht_nav_up",
            btnPrev: "#ht_nav_prev",
            vertical: true,
			speed: 500,
            beforeStart: beforeStorySlide,
            afterEnd: afterStorySlide
        });

        init();

        function init() {
            if (options.auto === true) {
                clearAndSetTimer();
            }
			if (options.startRandom === true) {
				//return a random integer between 0 and 10
				var n = $teasers.size();
				var start = Math.floor(Math.random()* (n ));			
				teaserCarousel.slideTo(start);
			}
        }

        function clearAndSetTimer() {			
            if (timer)
                clearTimeout(timer);	
			 if (options.auto === true) {		
				timer = setInterval(function() {
					teaserCarousel.prev();
				}, options.speed);
			}
        }

        function beforeStorySlide(visibleElements) {

        }

        function cancel() {

        }

        function afterStorySlide(visibleElements) {
        
            clearAndSetTimer(timer); // Reset timer
        }


    };

})(jQuery);
