var maxFonts;jQuery(document).ready(function(t){maxFonts=function(){},maxFonts.prototype={webFonts:!1,userFonts:!1,systemFonts:["","Arial","Courier New","Georgia","Tahoma","Times New Roman","Trebuchet MS","Verdana"],delay:null,googleBaseURL:"//fonts.googleapis.com/css?family=",displayOnLoad:!0,fontsLoaded:[]},maxFonts.prototype.load=function(){this.userFonts||this.loadUserFonts(),this.webFonts===!1?this.parseWebFonts():this.showFonts("web")},maxFonts.prototype.close=function(){window.maxFoundry.maxmodal.close()},maxFonts.prototype.checkFonts=function(){var o=this;t(".mb-text, .mb-text2").each(function(){var e=t(this).css("fontFamily"),n=o.getWebFamily(e);n!==!1&&t("head").append("<link rel='stylesheet' type='text/css' href='"+n+"' />")})},maxFonts.prototype.getWebFamily=function(o){if(this.systemFonts.indexOf(o)>=0)return!1;this.webFonts===!1&&this.parseWebFonts(),fonts=this.webFonts;var e=this,n=!1;return t(fonts).each(function(){if(this.family==o){var t=this.variants,a=this.family;if(a=a.replace("'",""),a=a.replace(/\s/g,"+"),a.indexOf(",",a)>=0)return!1;if(e.fontsLoaded.indexOf(a)>=0)return!1;e.fontsLoaded.push(a);var s=400;return t.indexOf("regular")>=0?s="400":t.indexOf("300")>=0?s="300":t.indexOf("500")>=0&&(s="500"),n=e.googleBaseURL+a+":"+s,!1}}),n},maxFonts.prototype.delay=function(){var t={};return function(o,e,n){n=n||"defaultTimer",clearTimeout(t[n]||0),t[n]=setTimeout(o,e)}}(),maxFonts.prototype.loadDone=function(){t(".max-modal.add-fonts").find(".loading, .loading_overlay").hide(),t(".max-modal.add-fonts .fontcount").text(this.webFonts.length),t(".max-modal.add-fonts .font_search").off("keyup"),t(".max-modal.add-fonts .font_search").on("keyup",t.proxy(function(){this.delay(t.proxy(function(){this.searchkw()},this),300,"search")},this)),t(".max-modal.add-fonts .font_manager .items input").off("click"),t(".max-modal.add-fonts .font_manager .items input").on("click",t.proxy(this.renderExample,this)),t('.max-modal.add-fonts button[name="save_fonts"]').off("click"),t('.max-modal.add-fonts button[name="save_fonts"]').on("click",t.proxy(this.saveFonts,this))},maxFonts.prototype.searchkw=function(){var o=t(".max-modal .font_search input").val();t(".max-modal .font_search input").prop("disabled",!0),o=o.toLowerCase(),t(".max-modal .font_manager .items li label input").each(function(){""==o||t(this).val().toLowerCase().indexOf(o)>=0?t(this).parents("li").show():t(this).parents("li").hide()}),t(".max-modal .font_search input").prop("disabled",!1)},maxFonts.prototype.renderExample=function(o){var e=o.target;"LI"!==e.nodeName&&(e=t(o.target).parents("li"));var n=t(e).find("input").val();t(".max-modal .font_manager .items li").css("border",""),t(e).css("border","1px solid #000"),family=this.getWebFamily(n),family&&t("head").append("<link rel='stylesheet' type='text/css' href='"+family+"' />"),t(".font_example .placeholder").hide(),t(".font_example .example_text").show().css("fontFamily",n)},maxFonts.prototype.saveFonts=function(){var o=t(".max-modal .font_manager .items li input:checked"),e={};t(o).each(function(){val=t(this).val(),e[val]=val});var n={action:"font_manager",font_action:"save",fonts:e};t.ajax({type:"POST",url:ajaxurl,data:n,success:t.proxy(this.saveDone,this)})},maxFonts.prototype.saveDone=function(o){var e=JSON.parse(o),n=e.fonts,a=e.usedfonts,s=t('#maxbuttons select[name="font"], #maxbuttons select[name="font2"]'),i=t(s).find(":selected");t(s).children("option").remove(),t.each(n,function(o,e){t(s).append('<option value="'+o+'">'+e+"</option>")}),t(s[0]).find('option[value="'+t(i[0]).val()+'"]').attr("selected","selected"),t(s[1]).find('option[value="'+t(i[1]).val()+'"]').attr("selected","selected"),mb_font_options.used_fonts=a,this.loadUserFonts(),this.showFonts("web"),this.close()},maxFonts.prototype.parseWebFonts=function(){var o=[],e=JSON.parse(mb_font_options.webfonts);t(e.items).each(function(){var t=(this.variants,{});t.family=this.family,t.variants=this.variants,o.push(t)}),this.webFonts=o,this.displayOnLoad&&this.showFonts("web")},maxFonts.prototype.loadUserFonts=function(){var o=[],e=mb_font_options.used_fonts;return""===e?void(this.userFonts=[]):(t.each(e,function(t,e){""!==e&&o.push(e)}),void(this.userFonts=o))},maxFonts.prototype.showFonts=function(o){if(userfonts=this.userFonts,"web"!==o)return!1;fonts=this.webFonts;var e=".max-modal .font_manager .font_left",n=".max-modal .font_manager .font_right";t(e).find(".items li").remove(),t(n).find(".items li").remove();var a,s=fonts.length,r=Math.ceil(s/2),l=e,f=!1;for(i=0;i<fonts.length;i++)i>=r&&(l=n),a=fonts[i].family,f=t.inArray(a,userfonts)>=0?"checked":"",t(l+" .items").append('<li><label><input type="checkbox" name="userfonts[]" value="'+a+'"'+f+">"+a+"</label></li>");this.loadDone()}});