var image_added;!function(r){var i,o,n,d,s,p;r(document).ready(function(){var e=r("#page_image_picker");p=e.data("input-type"),s="wym"==p,r("#custom_images_tab a").click(function(){if(!e.data("size-applied")&&s){var t=r(".page_part:first .wym_box"),a=r(".page_part:first iframe");e.css({height:t.height(),width:t.width()}).data("size-applied",!0).corner("tr 5px").corner("bottom 5px").find(".wym_box").css({backgroundColor:"white",height:a.height()+r(".page_part:first .wym_area_top").height()-parseInt(r(".wym_area_top .label_inline_with_link a").css("lineHeight")),width:a.width()-20,"border-color":a.css("border-top-color"),"border-style":a.css("border-top-style"),"border-width":a.css("border-top-width"),padding:"0px 10px 0px 10px"})}}),r("#page_images li textarea:hidden").each(function(t){var a=r(this).attr("name"),e=r(this);e.attr("data-old-id",e.attr("id")),e.attr("name","ignore_me_"+t),e.attr("id","ignore_me_"+t);var i=r("").addClass("caption").attr("type","hidden").attr("name",a).attr("id",e.attr("data-old-id")).val(e.val());e.parents("li").first().append(i)}),i(),r(".page-images-caption-modal").hide(),d=r("#page_images .js-page-images-template").detach()}),i=function(){s&&WYMeditor.onload_functions.push(function(){r(".wym_box").css({width:null})}),r("#page_images").sortable({tolerance:"pointer",placeholder:"placeholder",cursor:"drag",items:"li",stop:n}),r("#page_images").on("mouseenter mouseleave","li",function(t){var a=r(this),e=a.find(".image_actions");if("mouseenter"==t.type){if(0==e.length){e=r("
");var i=r("");if(i.appendTo(e),i.click(function(){r(this).parents("li").first().remove(),n()}),0");d.appendTo(e),d.click(o)}else e.addClass("no_captions");e.appendTo(a)}e.show()}else"mouseleave"==t.type&&e.hide()}),n()},image_added=function(t){var a=d.clone(),e=r(t).attr("id").replace("image_","");a.find("input:hidden:first").val(e),r("").attr({title:r(t).attr("title"),alt:r(t).attr("alt"),src:r(t).attr("data-grid")}).appendTo(a),a.attr("id","image_"+e).removeClass("empty"),a.appendTo(r("#page_images")),i()},o=function(){var t=r(this).closest("li"),a=t.find(".page-images-caption-modal > textarea"),e=a.parent(),i={textarea:{width:400,height:"auto"},wym:{width:928,height:530}};e.find(".js-page-images-done").on("click",function(){e.dialog("close")});var d=function(){s&&a.data("wymeditor").update(),r("li.current_caption_list_item").removeClass("current_caption_list_item"),r("#"+a.attr("data-old-id")).val(a.val()),e.dialog("destroy")};t.addClass("current_caption_list_item"),e.dialog({title:"Add Caption",modal:!0,resizable:!1,autoOpen:!0,width:i[p].width,height:i[p].height,close:d}),s?a.addClass("wymeditor active_rotator_wymeditor widest").wymeditor(wymeditor_boot_options):a.show()},n=function(){r("#page_images li textarea:hidden").each(function(t,a){var e=r(a).attr("name").split("_");e[2]=""+t,r(a).attr("name",e.join("_")),r(a).attr("id",r(a).attr("id").replace(/_\d/,"_"+t)),r(a).attr("data-old-id",r(a).attr("data-old-id").replace(/_\d_/,"_"+t+"_").replace(/_\d/,"_"+t))}),r("#page_images li").each(function(e,t){r("input:hidden",t).each(function(){var t=r(this),a=t.attr("name").split("]");a[1]="["+e,t.attr("name",a.join("]")),t.attr("id",t.attr("id").replace(/_\d_/,"_"+e+"_").replace(/_\d/,"_"+e))})})}}(jQuery);