/**
 * -----------------------------------
 * Slideshow Script
 *
 * (c) 2009 by Alexander Brakowski
 *     :: http://www.arctoz.de
 *     :: genix@arctoz.de
 *     
 * ----------------------------------
 *  Licensed to René Knipschild
 *  for usage on any domain
 * 
 *  Adapted (c) 2011 by A. Brakowski
 *     :: http://www.arctoz.de
 *     :: genix@arctoz.de
 *  as KnightRider-Script licensed
 *  to René Knipschild, again. To
 *  whoever else?!
 * 
 * ----------------------------------
 * ARCTOZ LICENSE-KEY:
 * 
 * 74329638D13BE502033060FEE034924A
 * 6A3DC35C5EAB1F9EBBFE1EBEB68418B3
 * 8902E694881308E4F95C04889D5D5F96
 * C0413E0D744C51D23BB0B133F52BFBE0
 * D5075DEC9FF84149197830D5F6DAE98B
 * B4A55DF386497445E1DAF4B543EA6AF6
 * E026540299131291255B9243C2A5B6B7
 * FEE6BE2886DBDB46C1692D790D39B9B3
 * ----------------------------------
 */
 
(function($){
    $.fn.knightRider = function(settings){
        var config = {
			// fade animation duration
			animationSpeed: 200,
			// next image fade
			duration:       200,
			// image default opacity, 
			// must be below 0.6 to get desired fade effect
			startOpacity:   0.3
        };
        
        if (settings) $.extend(config, settings);
       
        
        this.each(function() {
            var el = $(this);
            
            if(!el.children("img").length) return;
            el.children("img").css({opacity: config.startOpacity});
            
            var left2right = true;
            var next = el.children('img:first');
            
            setInterval(function() {
				next.animate({opacity: 1.0}, config.animationSpeed, function(){
					$(this).animate({opacity: config.startOpacity}, config.animationSpeed);
				});
                
                if(left2right){
					if(next.next().length){
						next = next.next();
					} else {
						left2right = false;
						next = next.prev();
					}
				} else {
					if(next.prev().length){
						next = next.prev();
					} else {
						left2right = true;
						next = next.next();
					}
				}
            }, config.duration);
        });
        
        return this;
    };
})(jQuery);

$(document).ready(function() {
	$("#knightrider").knightRider({duration: 240, animationSpeed: 240, startOpacity: 0.1}); 
});
