/* Black Studio TinyMCE Widget */ !function(e){function n(t){var i=null;return"string"==typeof t?i=t:"object"==typeof t&&t instanceof jQuery&&(i=e("textarea[id^=widget-black-studio-tinymce]",t.closest(bstw_data.container_selectors)).attr("id")),{activate:function(){if(e("#"+i).addClass("mceEditor"),"object"==typeof tinymce&&"function"==typeof tinymce.execCommand){this.deactivate();try{tinymce.execCommand("mceAddControl",!1,i)}catch(t){window.alert(t)}}return this},deactivate:function(){var t;return"object"==typeof tinymce&&"function"==typeof tinymce.execCommand&&this.is_tinymce_active()&&(t=tinymce.get(i).getContent(),tinymce.get(i).remove(),e("#"+i).val(t)),this},activate_after_open:function(){return"visual"===this.get_mode()&&(0===e("div.widget:has(#"+i+") :animated").size()&&!this.is_tinymce_active()&&this.is_textearea_visible()||this.is_tinymce_active()?this.set_mode("visual"):setTimeout(function(){n(i).activate_after_open()},100)),this},activate_after_ajax:function(){return"visual"===this.get_mode()&&(0===e.active&&!this.is_tinymce_active()&&this.is_textearea_visible()?this.set_mode("visual"):this.is_widget_inside_visible()&&!this.is_tinymce_active()&&setTimeout(function(){n(i).activate_after_ajax()},100)),this},get_widget:function(){return e("#"+i).closest("div.widget")},get_widget_inside:function(){return e("#"+i).closest("div.widget-inside")},get_editor_wrap:function(){return e("#"+i).closest("div.wp-editor-wrap")},get_textarea:function(){return e("#"+i)},get_id:function(){return i},get_tinymce:function(){return tinymce.get(i)},get_mode:function(){return e("input[id^=widget-black-studio-tinymce][id$=type]",this.get_widget_inside()).val()},set_mode:function(t){return"visual"===t&&(this.get_editor_wrap().removeClass("html-active").addClass("tmce-active"),this.activate()),"html"===t&&(this.get_editor_wrap().removeClass("tmce-active").addClass("html-active"),this.deactivate()),e("input[id^=widget-black-studio-tinymce][id$=type]",this.get_widget_inside()).val(t),this},is_tinymce_active:function(){return"object"==typeof tinymce&&"object"==typeof tinymce.get(i)&&null!==tinymce.get(i)},is_textearea_visible:function(){return e("#"+i).is(":visible")},is_widget_inside_visible:function(){return e(" div.widget-inside:has(#"+i+")").is(":visible")},check_duplicates:function(){return 1'+bstw_data.error_duplicate_id+""),this},fix_css:function(){return this.get_widget().css("position","relative").css("z-index","100000"),e("#wpbody-content").css("overflow","visible"),this},set_media_target:function(){return e(".insert-media",this.get_widget()).data("editor",i),this}}}e(document).ready(function(){e("div.widget[id*=black-studio-tinymce] .widget-title, div.widget[id*=black-studio-tinymce] a.widget-action").live("click",function(){n(e(this)).check_duplicates().fix_css().set_media_target().activate_after_open(),e("input[name=savewidget]",n(e(this)).get_widget()).click(function(){n(e(this)).is_tinymce_active()&&n(e(this)).deactivate(),e(this).unbind("ajaxSuccess").ajaxSuccess(function(){n(e(this)).activate_after_ajax()})})}),e("div.widget[id*=black-studio-tinymce] input[name=savewidget]").live("click",function(){n(e(this)).is_tinymce_active()&&n(e(this)).deactivate(),e(this).unbind("ajaxSuccess").ajaxSuccess(function(){n(e(this)).activate_after_ajax()})}),e("a[id^=widget-black-studio-tinymce][id$=tmce]").live("click",function(){n(e(this)).set_mode("visual")}),e("a[id^=widget-black-studio-tinymce][id$=html]").live("click",function(){n(e(this)).set_mode("html")}),e(".wp-media-buttons a").live("click",function(){edCanvas=n(e(this)).get_textarea().get(),wpActiveEditor=n(e(this)).get_id()}),0