!function(e){e(document).ready((function(){var t=e("#r3d-insert-btn"),o=e("#r3d-select-pdf"),i=e("#r3d-select-images"),l=e("#r3d-select-thumb"),n=e("#r3d-select-flipbook"),a=e("#r3d-pdf-url"),d=e("#r3d-thumb-url"),r=e(".r3d-pages"),s=[],c=[];function p(){var o=e("#r3d-select-flipbook option:selected").val(),i=a.val();o||i||s.length?t.prop("disabled",""):t.prop("disabled","disabled")}t.on("click",(function(){!function(){var t=e("#r3d-select-flipbook option:selected").val(),o=a.val(),i=d.val(),l="[real3dflipbook";o&&(l+=' pdf="'+o+'"');i&&(l+=' thumb="'+i+'" mode="lightbox"');t&&(l+=' id="'+t+'"');s.length&&(l+=' pages="'+s.join(",")+'"',l+=' thumbs="'+c.join(",")+'"');e("#r3d-mode").val()&&(l+=' mode="'+e("#r3d-mode").val()+'"');e("#r3d-class").val()&&(l+=' lightboxcssclass="'+e("#r3d-class").val()+'"');"no"==e("#r3d-class").val()&&(l+=' thumb=""');l+="]",window.send_to_editor(l),tb_remove()}()})),n.change(p),a.change((function(){r.empty(),s=[],c=[],p()})),e(".r3d-insert-flipbook-button").click((function(){setTimeout((function(){e("#TB_ajaxContent").addClass("r3d-TB_ajaxContent"),e("#TB_window").addClass("r3d-TB_window")}),0)})),o.on("click",(function(){var e=wp.media({title:"Select PDF",button:{text:"Send to Flipbook"},library:{type:["application/pdf"]},multiple:!1}).on("select",(function(){var t=e.state().get("selection").models[0].attributes.url;a.val(t).trigger("change")})).open()})),i.on("click",(function(){var t=wp.media({title:"Select images",button:{text:"Send to Flipbook"},library:{type:["image"]},multiple:!0}).on("select",(function(){var o=t.state().get("selection");a.val("").trigger("change"),e("<p>Pages</p>").appendTo(r);for(var i=0;i<o.models.length;i++){var l=o.models[i].attributes.sizes.full.url,n=void 0!==o.models[i].attributes.sizes.medium?o.models[i].attributes.sizes.medium.url:l;s.push(l),c.push(n),e("<img>").attr("src",n).appendTo(r).css({height:"50px",margin:"5px"})}p()})).open()})),l.on("click",(function(){var e=wp.media({title:"Select image",button:{text:"Send to Flipbook"},library:{type:["image"]},multiple:!1}).on("select",(function(){var t=e.state().get("selection").models[0].attributes.url;d.val(t).trigger("change")})).open()})),e("body").on("thickbox:removed",(function(){t.prop("disabled","disabled"),n.val(""),a.val(""),e(".r3d-setting").val(""),e("#TB_ajaxContent").removeClass("r3d-TB_ajaxContent"),e("#TB_window").removeClass("r3d-TB_window"),e(".r3d-row-lightbox").hide(),r.empty(),s=[],c=[]})),e("#r3d-mode").bind("change",(function(){"lightbox"==this.value?e(".r3d-row-lightbox").show():e(".r3d-row-lightbox").hide()}))}))}(jQuery);