$(function(){window.youtube=window.youtube||{};var t,e=document.getElementById("youtube-iframe-api"),o=(e?window.isYoutubeReady&&window.youtube.loadYoutubeInView():(window.isYoutubeReady=!1,(e=document.createElement("script")).setAttribute("id","youtube-iframe-api"),e.setAttribute("async",""),e.src="https://www.youtube.com/iframe_api",(t=document.getElementsByTagName("script")[0]).parentNode.insertBefore(e,t)),window.onYouTubeIframeAPIReady=function(){window.isYoutubeReady=!0,window.youtube.loadYoutubeInView()},window.youtube.calculateDimensions=function(t){var e=t.data("height"),o=t.data("width"),i=t.data("ratio");return i&&(o||(t.width("100%"),o=t.parent().width()),e||(i=(i=i||"16:9").split(":"),e=Math.round(o/i[0]*i[1]))),{width:o,height:e}},window.youtube.loadYoutubeInView=function(t){t=t||document,o(t,".youtube-video:not([data-yt-initialized])")},function(t,e){t=$(t||document);var n=$(window).scrollTop(),o=$(window).height(),a=n+o,u=$(),d=$(),w=t.find(e);setTimeout(function(){for(var i=0,t=0;t<w.length;t++){var e=$(w[t]);setTimeout(function(t){var e=t.offset().top,o=e+t.height();e<=a+400&&n-400<=o&&(t.closest(":not(a)").is(":visible")?u=u.add(t):d=d.add(t)),++i>=w.length&&(e=$.merge(u,d),r(e),w=w.not(e))}.bind(this,e),0)}},0)}),r=function(t){t.each(function(){var t=$(this),e=(t.attr("data-yt-initialized",1),t.attr("id")),o=t.data("videoId"),i=t.data("volume"),n=t.data("autoPlay"),a=t.data("controls"),u=t.data("loop"),d=t.data("showInfo"),t=window.youtube.calculateDimensions(t),w=new YT.Player(e,{height:t.height,width:t.width,videoId:o,playerVars:{autoplay:n,controls:a,loop:u,showinfo:d,modestbranding:"1",playlist:o,rel:"0",playsinline:"1"},events:{onReady:function(t){w.setVolume(i),0==i&&w.mute();n&&w.playVideo()}}})})};window.youtube.fixDimensions=function(t){var t=t.find(".youtube-video"),e=window.youtube.calculateDimensions(t);t.attr("width",e.width),t.attr("height",e.height)},$(window).on("throttledScroll resize",function(){window.youtube.loadYoutubeInView()})});