// source --> https://magazine.voicenote.jp/wp-content/themes/affinger4-child/js/jquery.bgswitcher.js 
/*!
 * jQuery.BgSwitcher
 *
 * @version  0.4.3
 * @author   rewish <rewish.org@gmail.com>
 * @license  MIT License (https://github.com/rewish/jquery-bgswitcher/blob/master/LICENSE.md)
 * @link     https://github.com/rewish/jquery-bgswitcher
 */
(function(d){var a={},g=Array.prototype.slice,f=Object.prototype.toString,b=["Top","Right","Bottom","Left"],e=["Attachment","Color","Image","Repeat","Position","Size","Clip","Origin"];d.fn.bgswitcher=function(){var h=arguments,i=c.keys.instance;return this.each(function(){var j=d.data(this,i);if(!j){j=new c(this);d.data(this,i,j)}j.dispatch.apply(j,h)})};d.fn.bgSwitcher=d.fn.bgswitcher;function c(h){this.$el=d(h);this.index=0;this.config=d.extend({},c.defaultConfig);this._setupBackgroundElement();this._listenToResize()}d.extend(c.prototype,{dispatch:function(h){switch(f.call(h)){case"[object Object]":this.setConfig(h);break;case"[object String]":this[h].apply(this,g.call(arguments,1));break;default:throw new Error("Please specify a Object or String")}},setConfig:function(h){this.config=d.extend(this.config,h);if(typeof this.config.random!=="undefined"){this.config.shuffle=this.config.random}this.refresh()},setImages:function(h){this.imageList=new this.constructor.ImageList(h);if(this.config.shuffle){this.imageList.shuffle()}},setSwitchHandler:function(h){this.switchHandler=d.proxy(h,this)},getBuiltInSwitchHandler:function(h){return this.constructor.switchHandlers[h||this.config.effect]},refresh:function(){this.setImages(this.config.images);this.setSwitchHandler(this.getBuiltInSwitchHandler());this._prepareSwitching();if(this.config.start){this.start()}},start:function(){if(!this._timerID){this._timerID=setTimeout(d.proxy(this,"next"),this.config.interval)}},stop:function(){if(this._timerID){clearTimeout(this._timerID);this._timerID=null}},toggle:function(){if(this._timerID){this.stop()}else{this.start()}},reset:function(){this.index=0;this._prepareSwitching()},next:function(){var h=this.imageList.count();if(!this.config.loop&&this.index+1===h){return}if(++this.index===h){this.index=0}this.switching()},prev:function(){if(!this.config.loop&&this.index===0){return}if(--this.index===-1){this.index=this.imageList.count()-1}this.switching()},select:function(h){if(h===-1){h=this.imageList.count()-1}this.index=h;this.switching()},switching:function(){var h=!!this._timerID;if(h){this.stop()}this._createSwitchableElement();this._prepareSwitching();this.switchHandler(this.$switchable);if(h){this.start()}},destroy:function(){this.stop();this._stopListeningToResize();if(this.$switchable){this.$switchable.stop();this.$switchable.remove();this.$switchable=null}if(this.$bg){this.$bg.remove();this.$bg=null}this.$el.removeAttr("style");this.$el.removeData(this.constructor.keys.instance);this.$el=null},_adjustRectangle:function(){var l,j=0,k=b.length,m=this.$el.position(),h={top:m.top,left:m.left,width:this.$el.innerWidth(),height:this.$el.innerHeight()};for(;j<k;j++){l=b[j];h["margin"+l]=this.$el.css("margin"+l);h["border"+l]=this.$el.css("border"+l)}this.$bg.css(h)},_setupBackgroundElement:function(){this.$bg=d(document.createElement("div"));this.$bg.css({position:"absolute",zIndex:(parseInt(this.$el.css("zIndex"),10)||0)-1,overflow:"hidden"});this._copyBackgroundStyles();this._adjustRectangle();if(this.$el[0].tagName==="BODY"){this.$el.prepend(this.$bg)}else{this.$el.before(this.$bg);this.$el.css("background","none")}},_createSwitchableElement:function(){if(this.$switchable){this.$switchable.remove()}this.$switchable=this.$bg.clone();this.$switchable.css({top:0,left:0,margin:0,border:"none"});this.$switchable.appendTo(this.$bg)},_copyBackgroundStyles:function(){var m,l={},j=0,k=e.length,h="backgroundPosition";for(;j<k;j++){m="background"+e[j];l[m]=this.$el.css(m)}if(l[h]===undefined){l[h]=[this.$el.css(h+"X"),this.$el.css(h+"Y")].join(" ")}this.$bg.css(l)},_listenToResize:function(){var h=this;this._resizeHandler=function(){h._adjustRectangle()};d(window).on("resize",this._resizeHandler)},_stopListeningToResize:function(){d(window).off("resize",this._resizeHandler);this._resizeHandler=null},_prepareSwitching:function(){this.$bg.css("backgroundImage",this.imageList.url(this.index))}});c.keys={instance:"bgSwitcher"};c.defaultConfig={images:[],interval:5000,start:true,loop:true,shuffle:false,effect:"fade",duration:1000,easing:"swing"};c.switchHandlers={fade:function(h){h.animate({opacity:0},this.config.duration,this.config.easing)},blind:function(h){h.animate({height:0},this.config.duration,this.config.easing)},clip:function(h){h.animate({top:parseInt(h.css("top"),10)+h.height()/2,height:0},this.config.duration,this.config.easing)},slide:function(h){h.animate({top:-h.height()},this.config.duration,this.config.easing)},drop:function(h){h.animate({left:-h.width(),opacity:0},this.config.duration,this.config.easing)},hide:function(h){h.hide()}};c.defineEffect=function(h,i){this.switchHandlers[h]=i};c.ImageList=function(h){this.images=h;this.createImagesBySequence();this.preload()};d.extend(c.ImageList.prototype,{isSequenceable:function(){return typeof this.images[0]==="string"&&typeof this.images[1]==="number"&&typeof this.images[2]==="number"},createImagesBySequence:function(){if(!this.isSequenceable()){return}var i=[],k=this.images[0],j=this.images[1],h=this.images[2];do{i.push(k.replace(/\.\w+$/,j+"$&"))}while(++j<=h);this.images=i},preload:function(){var k,j=this.images.length,h=0;for(;h<j;h++){k=this.images[h];if(!a[k]){a[k]=new Image();a[k].src=k}}},shuffle:function(){var h,m,l=this.images.length,k=this.images.join();if(!l){return}while(l){h=Math.floor(Math.random()*l);m=this.images[--l];this.images[l]=this.images[h];this.images[h]=m}if(this.images.join()===k){this.shuffle()}},get:function(h){return this.images[h]},url:function(h){return"url("+this.get(h)+")"},count:function(){return this.images.length}});d.BgSwitcher=c}(jQuery));