/*
 Copyright (C) 2020 Jessica González
 @license http://www.mozilla.org/MPL/ MPL 2.0
 @version 1.2.11
*/

var _oh=function(){this.masterDiv=$(".oharaEmbed");this.basedElement=this.masterDiv.parent();this.defaultWidth="undefined"!==typeof _ohWidth?_ohWidth:480;this.defaultHeight="undefined"!==typeof _ohHeight?_ohHeight:270;this.aspectRatio=this.defaultHeight/this.defaultWidth;this.basedWidth=this.basedElement.width()>=this.defaultWidth?this.defaultWidth:this.basedElement.width();this.basedHeight=this.basedElement.height()>=this.defaultHeight?this.defaultHeight:this.basedElement.height();this.main();this.responsive()};
_oh.prototype.main=function(){var b=this;$(".youtube").each(function(){var a=$(this);a.videoID=this.id.replace("oh_","");a.imgsrc=b.getImage(a.videoID);a.imgHeight=b.basedHeight;a.imgWidth=b.basedWidth;"undefined"!==typeof a.imgsrc&&a.css({"background-image":"url("+a.imgsrc+")","background-size":"cover"});a.append($("<div/>",{"class":"youtube_play"}));a.one("click",function(){var b="//www.youtube.com/embed/"+a.videoID+"?autoplay=1&autohide=1";a.data("params")&&(b+="&"+a.data("params"));b=$("<iframe/>",
{frameborder:"0",src:b,width:a.imgWidth,height:a.imgHeight,allowfullscreen:"allowfullscreen"});a.css({"background-image":"none"}).append(b);a.children(".youtube_play").css({height:"0"})})});b.responsive()};
_oh.prototype.responsive=function(){$this=this;$(window).resize(function(){var b=$this.basedElement.width();newHeight=b*$this.aspectRatio<=$this.defaultHeight?b*$this.aspectRatio:$this.defaultHeight;var a=b<=$this.defaultWidth,c=a?b:$this.defaultWidth,d=a?newHeight:$this.defaultHeight;0>=c&&0>=d&&(c=$this.defaultWidth,d=$this.defaultHeight);$this.masterDiv.width(c).height(d);$(".oharaEmbed > iframe").each(function(){$(this).width(c).height(d)})}).resize()};
_oh.prototype.refresh=function(){$this=this;setTimeout(function(){$this.main()},3E3);setTimeout(function(){$this.responsive()},3E3)};_oh.prototype.getImage=function(b){var a="",c,d,e=["hqdefault","mqdefault","sddefault","maxresdefault"];c=0;for(d=e.length;c<d&&(a="//i.ytimg.com/vi/"+b+"/"+e[c]+".jpg",0==a.width);++c);0==a.width&&(a="//i.ytimg.com/vi/"+b+"/default.jpg");return a};(function(b){b(function(){var a=new _oh;b("input[name=preview]").on("click",function(){a.refresh()})})})(jQuery);
