
(function ($) {
    $.fn.slideShow = function (settings) {
        var index = -1;

        var config = {
            slides: [],
            interval: 30000
        };

        if (settings) $.extend(config, settings);

        init = function (el) {
            if (config.slides.length > 0) {
                var imgelement = $("<img />").attr("id", "slide");

                $(el).append(imgelement);
                imgelement.hide();

                nextSlide(el);
            }
        }

        nextSlide = function (el) {
            index = Math.floor(Math.random() * config.slides.length);
            
            //index++;
            if (index >= config.slides.length) { index = 0; }            
            $("<img />")
					.attr("src", config.slides[index].image)
					.load(function () {
					    $("img", el).attr("src", config.slides[index].image);
					    $("img", el).show();
					    $('#supersize').resizenow();
					});

            setTimeout(function () { nextSlide(el); }, config.interval);            
        }


        this.each(function () {
            //setup element            
            init(this);
        });

        return this;

    };


})(jQuery);
