

(function ($) {
    $.randomImage = {
        defaults: {
            //you can change these defaults to your own preferences.
            path: 'images/home/', //change this to the path of your images
            myImages: ['01.jpg', '02.jpg', '03.jpg', '04.jpg', '05.jpg', '06.jpg', '07.jpg', '08.jpg', '09.jpg', '10.jpg', '11.jpg', '12.jpg'] 
        }
    };

    $.fn.extend({
        randomImage: function (param) {

            var config = $.extend({}, $.randomImage.defaults, param);

            return this.each(function () {

                var imageNames = config.myImages;

                // get size of array, randomize a number from this
                // use this number as the array index

                var imageNamesSize = imageNames.length;

                var lotteryNumber = Math.floor(Math.random() * imageNamesSize);
                
                var winnerImage = imageNames[lotteryNumber];

                var fullPath = config.path + winnerImage;


                //put this image into DOM at class of randomImage
                // alt tag will be image filename.
                $(this).attr({
                    src: fullPath,
                    alt: winnerImage
                });
            });
        }
    });
})(jQuery);
