var bbwizard,requestRunning=!1;!function(o){"use strict";bbwizard=function(e,i){if(!requestRunning){var n=o("#bbcode_wizard"),t=o("#darkenwrapper");if(!n.is(":visible")){requestRunning=!0;var a=phpbb.loadingIndicator();o.ajax({url:e,dataType:"html",beforeSend:function(){n.hide().empty()},success:function(e){t.fadeIn("fast"),n.append(e).fadeIn("fast")},error:function(){bbfontstyle("["+i+"]","[/"+i+"]")},complete:function(){requestRunning=!1,a&&a.is(":visible")&&a.fadeOut(phpbb.alertTime)}})}}};var r=function(e,i){var n;if(is_ie&&((n=document.forms[form_name].elements[text_name]).focus(),baseHeight=document.selection.createRange().duplicate().boundingHeight),insert_text(e+i),is_ie){var t=e+i,a=n.innerHTML.indexOf(t);if(0<a){var o=a+t.length,r=n.createTextRange();r.move("character",o),r.select(),storeCaret(n),n.focus()}}};o(document).ready(function(){var e=o("body");e.on("click",".spoilbtn",function(e){e.preventDefault();var i=o(this),n=i.closest("div").next(".spoilcontent");n.slideToggle("fast",function(){i.text(n.is(":visible")?i.data("hide"):i.data("show"))})});var i=o("#bbcode_wizard"),n=o("#darkenwrapper"),a=function(){i.is(":visible")&&(i.fadeOut("fast"),n.fadeOut("fast"))};e.on("click",a).on("keyup",function(e){27===e.keyCode&&(e.preventDefault(),a())}),i.on("click","#bbcode_wizard_submit",function(e){e.preventDefault();var i=o(this).data("bbcode");switch(i){case"url":var n=o("#bbcode_wizard_link").val(),t=o("#bbcode_wizard_description").val();r("["+i+(t.length?"="+n:"")+"]"+(t.length?t:n),"[/"+i+"]");break;case"bbvideo":r("[bbvideo]"+o("#bbvideo_wizard_link").val(),"[/bbvideo]")}a()}).on("click","#bbcode_wizard_cancel",function(e){e.preventDefault(),a()}).on("change","#bbvideo_wizard_sites",function(){o("#bbvideo_wizard_example").val(o(this).val())}).click(function(e){e.stopPropagation()})})}(jQuery);