(function($) {
    
    $.slider = function() {
        var fadeElements = function($elem, $objects, settings, current) {
            
            var next = (current == $objects.length-1) ? 0 : current + 1;

            $curobj = $objects.eq(current);
            $curobj.css('z-index', '5');
            $nextobj = $objects.eq(next);
            $nextobj.css('z-index', '10');
            
            
            
            $curobj.fadeOut(settings.speed, function() {});
            $nextobj.fadeIn(settings.speed, function() {
                var timeOut = setTimeout(function() {
                    fadeElements($elem, $objects, settings, next);
                }, settings.pause);
            });
            
            
            
        };
        return {
            initFade: function($elem, settings) {
                
                var $objects = $elem.find('.big-picture-obj');
                
                var rn = Math.floor(Math.random() * $objects.length);
                rn = 0;
                $objects.eq(rn).show();
                
                
                if($objects.length>1) {
                    var timeOut = setTimeout(function() {
                        fadeElements($elem, $objects, settings, rn);
                    }, settings.pause);
                }
                
            }
        };
    }();
    
    $.fn.extend({
        slider: function(options) {
            this.each(function() {

                // Settings
                var settings = $.extend({
                    pause : 2800,
                    speed: 2200
                }, options);
                
                $.slider.initFade($(this), settings); 
            });
            return this;
        }
    });
    
})(jQuery);

