/**
 * jQuery Simple Slideshow
 *
 * Version 1.0
 * Copyright (c) 2010 Andrew Childs
 *
 * Example Usage:
 *
 * $(document).ready(function() {
 *     $('.slideshow').simpleSlideshow();
 * });
 *
 * <div class="slideshow">
 *   <img src="/path/to/image1.jpg" alt="" />
 *   <img src="/path/to/image2.jpg" alt="" />
 *   <img src="/path/to/image3.jpg" alt="" />
 *   <img src="/path/to/image4.jpg" alt="" />
 * </div>
 */
;(function($) {
    $.fn.simpleSlideshow = function(settings) {
        var config = {
            cycle: 5,
            fade: 0.8,
            z: 999
        };
        if (settings) $.extend(config, settings);
        this.each(function() {
            var container = $(this);
            container.css({ position: 'relative', zIndex: config.z });
            $('img', container).hide();
            $('img:first', container).show();
            var cycle = function() {
                var next = $('img:visible', container).next('img');
                if (!next.length) {
                    next = $('img:first', container);
                }
                $('img', container).css({ zIndex: config.z });
                var old = $('img:visible', container);
                next.css({ position: 'absolute', top: '0px', zIndex: config.z + 1 }).fadeIn(config.fade * 1000, function() {
                    old.hide();
                    $(this).css({ position: 'static' });
                });
                setTimeout(cycle, config.cycle * 1000);
            };
            setTimeout(cycle, config.cycle * 1000);
        });
        return this;
    };
})(jQuery);

