(self.AMP=self.AMP||[]).push({n:"amp-youtube",v:"1493855940942",f:(function(AMP){var k;(function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global?global:a})(this);function n(a,b){function c(){}c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a;for(var d in b)if(Object.defineProperties){var g=Object.getOwnPropertyDescriptor(b,d);g&&Object.defineProperty(a,d,g)}else a[d]=b[d]};var p=/(?:^[#?]?|&)([^=&]+)(?:=([^&]*))?/g;function q(a){var b=Object.create(null);if(!a)return b;for(var c;c=p.exec(a);){var d=decodeURIComponent(c[1]).trim(),g=c[2]?decodeURIComponent(c[2]).trim():"";b[d]=g}return b};var r="";function t(a){var b=a||self,c;if(b.AMP_MODE)c=b.AMP_MODE;else{c=b;if(c.context&&c.context.mode)c=c.context.mode;else{var d=q(c.location.originalHash||c.location.hash),g=q(c.location.search);r||(r=c.AMP_CONFIG&&c.AMP_CONFIG.v?c.AMP_CONFIG.v:"011493855940942");c={localDev:!1,development:!("1"!=d.development&&!c.AMP_DEV_MODE),filter:d.filter,minified:!0,lite:void 0!=g.amp_lite,test:!1,log:d.log,version:"1493855940942",rtvVersion:r}}c=b.AMP_MODE=c}return c};var u=Object.prototype.toString;Date.now();self.log=self.log||{user:null,dev:null};var v=self.log;function w(){if(v.user)return v.user;throw Error("failed to call initLogConstructor");};function x(a,b){var c;a=a.__AMP_TOP||a;if(!y(a,b)){var d=a,d=d.__AMP_TOP||d;z(d,d,b,void 0,c);A(d,b)}return A(a,b)}function B(a,b,c,d,g){var e=C(a),f=D(e);z(f,e,b,c,d);g&&A(f,b)}function E(a,b){a=C(a);var c=D(a);y(c,b)||B(a,b,void 0,void 0,!0);return A(c,b)}function C(a){return a.nodeType?x((a.ownerDocument||a).defaultView,"ampdoc").getAmpDoc(a):a}function D(a){a=C(a);return a.isSingleDoc()?a.win:a}
function A(a,b){y(a,b);var c=F(a);a=c[b];a.obj||(a.obj=a.build(),a.resolve&&a.resolve(a.obj),a.build=null);return a.obj}function z(a,b,c,d,g){var e=F(a),f=e[c];f||(f=e[c]={obj:null,promise:null,resolve:null,build:null});f.build||f.obj||(f.build=function(){return d?new d(b):g(b)},f.resolve&&A(a,c))}function F(a){var b=a.services;b||(b=a.services={});return b}function y(a,b){a=a.services&&a.services[b];return!(!a||!a.build&&!a.obj)};function G(a){a.parentElement&&a.parentElement.removeChild(a)}function H(a){var b,c,d=b||function(a){return a},g=a.dataset;a=Object.create(null);var e=c?c:/^param(.+)/,f;for(f in g){var h=f.match(e);if(h){var l=h[1][0].toLowerCase()+h[1].substr(1);a[d(l)]=g[f]}}return a};var I,J="Webkit webkit Moz moz ms O o".split(" ");function L(a,b){for(var c in b){var d=a,g=b[c],e;e=d.style;var f=c;I||(I=Object.create(null));var h=I[f];if(!h){h=f;if(void 0===e[f]){var l;l=f;l=l.charAt(0).toUpperCase()+l.slice(1);a:{for(var m=0;m<J.length;m++){var K=J[m]+l;if(void 0!==e[K]){l=K;break a}}l=""}void 0!==e[l]&&(h=l)}I[f]=h}(e=h)&&(d.style[e]=g)}};function M(a,b,c){function d(a){try{return f(a)}catch(m){throw self.reportError(m),m;}}var g=void 0,e=a,f=c,h=g||!1;e.addEventListener(b,d,h);return function(){e&&e.removeEventListener(b,d,h);d=e=f=null}};function N(a,b,c){return M(a,b,c)}function O(a,b){var c=b,d=M(a,"load",function(a){try{c(a)}finally{c=null,d()}});return d}function P(a){var b,c,d=new Promise(function(b){c=O(a,b)});d.then(c,c);b&&b(c);return d};function Q(a){this.b=a;this.f=null;this.B=!1}Q.prototype.register=function(a){var b=a;b.registerAction("play",b.play.bind(b,!1));b.registerAction("pause",b.pause.bind(b));b.registerAction("mute",b.mute.bind(b));b.registerAction("unmute",b.unmute.bind(b));if(a.element.hasAttribute("autoplay")&&a.supportsPlatform()){this.f=this.f||[];var c=new R(this.b,a);S(this,c);this.f.push(c)}};
function S(a,b){N(b.video.element,"amp:video:visibility",function(){b.updateVisibility()});if(!a.B){var c=function(){for(var b=0;b<a.f.length;b++)a.f[b].updateVisibility()},d=E(a.b,"viewport");d.onScroll(c);d.onChanged(c);a.B=!0}}
function R(a,b){var c=this;this.b=a;this.video=b;this.F=null;this.C=this.c=this.A=!1;this.u=x(a.win,"vsync");this.w=T.bind(null,a.win,t(a.win).lite);a=b.element;this.i=a.hasAttribute("autoplay");P(a).then(function(){c.updateVisibility();c.A=!0;c.c&&c.i&&U(c)});this.updateVisibility();this.i&&aa(this)}function aa(a){a.video.isInteractive()&&a.video.hideControls();a.w().then(function(b){!b&&a.video.isInteractive()?a.video.showControls():(a.video.mute(),a.video.isInteractive()&&ba(a))})}
function ba(a){function b(b){a.u.mutate(function(){d.classList.toggle("amp-video-eq-play",b)})}function c(){this.C=!0;this.video.showControls();this.video.unmute();e();f();h();d.remove();g.remove()}a.video.hideControls();var d=ca(a),g=da(a);a.u.mutate(function(){a.video.element.appendChild(d);a.video.element.appendChild(g)});var e=N(g,"click",c.bind(a)),f=N(a.video.element,"pause",b.bind(a,!1)),h=N(a.video.element,"play",b.bind(a,!0))}
function U(a){!a.C&&E(a.b,"viewer").isVisible()&&a.w().then(function(b){b&&(a.c?a.video.play(!0):a.video.pause())})}
function ca(a){var b=a.b.win.document,c=b.createElement("i-amphtml-video-eq");c.classList.add("amp-video-eq");for(var d=1;4>=d;d++){var g=b.createElement("div");g.classList.add("amp-video-eq-col");for(var e=1;2>=e;e++){var f=b.createElement("div");f.classList.add("amp-video-eq-"+d+"-"+e);g.appendChild(f)}c.appendChild(g)}var h=x(a.b.win,"platform");h.isIos()&&c.setAttribute("unpausable","");return c}
function da(a){a=a.b.win.document.createElement("i-amphtml-video-mask");a.classList.add("i-amphtml-fill-content");return a}R.prototype.updateVisibility=function(){function a(){c.c!=d&&c.A&&c.i&&U(c)}function b(){if(c.video.isInViewport()){var a=c.video.element.getIntersectionChangeEntry(),b=a.intersectionRatio,d="number"===typeof b&&isFinite(b)?100*a.intersectionRatio:0;c.c=75<=d}else c.c=!1}var c=this,d=this.c;this.u.run({measure:b,mutate:a})};var V=null;
function T(a,b){if(V)return V;if(b)return V=Promise.resolve(!1);var c=a.document.createElement("video");c.setAttribute("muted","");c.setAttribute("playsinline","");c.setAttribute("webkit-playsinline","");c.muted=!0;c.playsinline=!0;c.webkitPlaysinline=!0;c.setAttribute("height","0");c.setAttribute("width","0");L(c,{position:"fixed",top:"0",width:"0",height:"0",opacity:"0"});try{var d=c.play();d&&d.catch&&d.catch(function(){})}catch(g){}return V=Promise.resolve(!c.paused)};function W(a){AMP.BaseElement.call(this,a);this.g=0;this.h=null;this.j=!1;this.o=this.m=this.l=this.s=this.a=null}n(W,AMP.BaseElement);k=W.prototype;k.preconnectCallback=function(a){this.preconnect.url(X(this));this.preconnect.url("https://s.ytimg.com",a);this.preconnect.url("https://i.ytimg.com",a)};k.isLayoutSupported=function(a){return"fixed"==a||"fixed-height"==a||"responsive"==a||"fill"==a||"flex-item"==a};k.renderOutsideViewport=function(){return.75};
k.viewportCallback=function(a){this.element.dispatchCustomEvent("amp:video:visibility",{visible:a})};k.buildCallback=function(){var a=this;this.h=Y(this);this.l=new Promise(function(b){a.m=b});this.getPlaceholder()||ea(this);B(this.element,"video-manager",Q);E(this.element,"video-manager").register(this)};
function X(a){if(a.s)return a.s;var b="https://www.youtube.com/embed/"+encodeURIComponent(a.h||"")+"?enablejsapi=1",c=H(a.element);"autoplay"in c&&(delete c.autoplay,w().error("AMP-YOUTUBE","Use autoplay attribute instead of data-param-autoplay"));"playsinline"in c||(c.playsinline="1");var d=a.element.hasAttribute("autoplay");d&&("iv_load_policy"in c||(c.iv_load_policy="3"),c.playsinline="1");var g=[],e;for(e in c){var f=c[e];if(null!=f)if(Array.isArray(f))for(var h=0;h<f.length;h++){var l=f[h];g.push(encodeURIComponent(e)+
"="+encodeURIComponent(l))}else g.push(encodeURIComponent(e)+"="+encodeURIComponent(f))}if(c=g.join("&"))b=b.split("#",2),e=b[0].split("?",2),c=e[0]+(e[1]?"?"+e[1]+"&"+c:"?"+c),b=c+=b[1]?"#"+b[1]:"";return a.s=b}
k.layoutCallback=function(){var a=this,b=this.element.ownerDocument.createElement("iframe"),c=X(this);b.setAttribute("frameborder","0");b.setAttribute("allowfullscreen","true");b.src=c;this.applyFillContent(b);this.a=b;this.o=N(this.win,"message",this.D.bind(this));this.element.appendChild(this.a);var d=this.loadPromise(this.a).then(function(){a.a.contentWindow.postMessage(JSON.stringify({event:"listening"}),"*");a.element.dispatchCustomEvent("load")});this.m(d);return d};
k.unlayoutCallback=function(){var a=this;this.a&&(G(this.a),this.a=null);this.o&&this.o();this.g=2;this.l=new Promise(function(b){a.m=b});return!0};k.pauseCallback=function(){this.a&&this.a.contentWindow&&1==this.g&&this.pause()};k.mutatedAttributesCallback=function(a){void 0!==a["data-videoid"]&&(this.h=Y(this),this.a&&Z(this,"loadVideoById",[this.h]))};
function Y(a){return w().assert(a.element.getAttribute("data-videoid"),"The data-videoid attribute is required for <amp-youtube> %s",a.element)}function Z(a,b,c){a.l.then(function(){if(a.a&&a.a.contentWindow){var d=JSON.stringify({event:"command",func:b,args:c||""});a.a.contentWindow.postMessage(d,"*")}})}
k.D=function(a){var b;(b="https://www.youtube.com"==a.origin&&a.source==this.a.contentWindow)&&(b=a.data)&&!(b="[object Object]"===u.call(a.data))&&(b=a.data,b=1>b.length?!1:0==b.lastIndexOf("{",0));if(b){var c;if("[object Object]"===u.call(a.data))c=a.data;else a:{try{c=JSON.parse(a.data);break a}catch(d){}c=void 0}a=c;void 0!==a&&("infoDelivery"==a.event&&a.info&&void 0!==a.info.playerState?(this.g=a.info.playerState,2==this.g?this.element.dispatchCustomEvent("pause"):1==this.g&&this.element.dispatchCustomEvent("play")):
"infoDelivery"==a.event&&a.info&&void 0!==a.info.muted&&this.j!=a.info.muted&&(this.j=a.info.muted,this.element.dispatchCustomEvent(this.j?"muted":"unmuted")))}};
function ea(a){var b=a.element.ownerDocument.createElement("img"),c=a.h||"";L(b,{"object-fit":"cover",visibility:"hidden"});b.src="https://i.ytimg.com/vi/"+encodeURIComponent(c)+"/sddefault.jpg#404_is_fine";b.setAttribute("placeholder","");b.setAttribute("referrerpolicy","origin");a.applyFillContent(b);a.element.appendChild(b);a.loadPromise(b).then(function(){if(120==b.naturalWidth&&90==b.naturalHeight)throw Error("sddefault.jpg is not found");}).catch(function(){b.src="https://i.ytimg.com/vi/"+encodeURIComponent(c)+
"/hqdefault.jpg";return a.loadPromise(b)}).then(function(){L(b,{visibility:""})})}k.supportsPlatform=function(){return!0};k.isInteractive=function(){return!0};k.play=function(){Z(this,"playVideo")};k.pause=function(){Z(this,"pauseVideo")};k.mute=function(){Z(this,"mute")};k.unmute=function(){Z(this,"unMute")};k.showControls=function(){};k.hideControls=function(){};AMP.registerElement("amp-youtube",W);
})});
//# sourceMappingURL=amp-youtube-0.1.js.map

