jQuery(function(s){var i=s(".st");function t(){s(input_selector).each(function(t){var e=s(this);if(1==e.next(".st_trigger").length)return!0;e.parent().addClass("has-smarttags"),e.parent().append('<span title="'+Joomla.JText._("NR_SMARTTAGS_SHOW")+'" class="icon-tags st_trigger" data-id="'+t+'"></span>'),input_type=e.prop("nodeName").toLowerCase(),e.parent().addClass("is_"+input_type)})}function o(t){t=void 0===t?0:t;$el_tabs.find(".st_tab_content").hide().eq(t).show(),$el_nav.find("a").removeClass("active").eq(t).addClass("active")}function c(){s(".has-smarttags").removeClass("active"),s("body").removeClass("smarttags-active"),i.hide()}$el_box=i.find(".box"),$el_nav=i.find(".st_nav"),$el_tabs=i.find(".st_tabs"),$el_search=i.find(".st_input_search"),$active_element=null,input_selector=Joomla.getOptions("SmartTagsBox").selector,t(),i.on("update",function(){t()}),$el_search.on("keyup",function(){var e=s(this).val(),e=($el_tabs.find(".st_search").remove(),0==e.length&&o(),s.trim(e.toLowerCase())),a=[];$el_tabs.find(".st_tab_content:not(.st_nosearch) > .st_item").each(function(){var t=s(this);-1<s.trim(t.text().toLowerCase()).indexOf(e)&&(t=t.clone().wrap("<p>").parent().html(),a.push(t))}),$el_tabs.append('<div class="st_tab_content st_search st_nosearch"></div>'),$el_tab_search=$el_tabs.find(".st_search"),0==a.length?$el_tab_search.html(Joomla.JText._("NR_SMARTTAGS_NOTFOUND")):$el_tab_search.html(a.join("")),o($el_tab_search.index())}),s(document).on("click","span.st_trigger",function(){var t,e,a,n;return t=s(this),(i.is(":visible")?c:($active_element=t,e=Joomla.getOptions("SmartTagsBox").tags,tags=s.extend({},e),s(document).trigger("smartTagsBoxBeforeRender",[tags,$active_element]),a="",s.each(tags,function(t){a+='<a href="#">'+t+"</a>"}),i.find(".st_container .st_nav").html(a),n="",s.each(tags,function(t,e){n+='<div class="st_tab_content" data-key="'+t+'">',s.each(e,function(t,e){if(!e)return!0;n+='<a class="st_item" data-key="'+t+'">'+e+" <small>"+t+"</small>"}),n+="</div>"}),i.find(".st_container .st_tabs").html(n),e=t.parent(),container_height=e.outerHeight(),e.addClass("active"),s("body").addClass("smarttags-active"),t="bottom"==(310<(t=s(window).height()-(e.offset().top+e.height()))?"bottom":"top")?e.offset().top+container_height:e.offset().top-310,i.find(".st_box").css({top:t+"px",left:e.offset().left+"px"}).end().show(),o))(),!1}),s(document).on("click",".st_nav a",function(){return o(s(this).index()),!1}),s(document).on("click",".st_tabs a",function(){var t,e;return t=s(this).data("key"),e=$active_element.parent().find(input_selector),$active_element.parent().find(".mce-tinymce, .tox-tinymce").length?tinymce.get(e.attr("id")).execCommand("mceInsertContent",!1," "+t):(t=s.trim(e.val()+" "+t),e.val(t).trigger("change")),!1}),s(document).on("click",".st_overlay",function(){return c(),!1})});

