function wpo_parse_json(s){if("object"==typeof s)return s;try{var e=JSON.parse(s);return e}catch(o){console.log("WPO: Exception when trying to parse JSON (1) - will attempt to fix/re-parse"),console.log(s)}var i=s.indexOf("{"),a=s.lastIndexOf("}");if(i>-1&&a>-1){var n=s.slice(i,a+1);try{var t=JSON.parse(n);return console.log("WPO: JSON re-parse successful"),t}catch(o){console.log("WPO: Exception when trying to parse JSON (2) - will attempt to fix/re-parse based upon bracket counting");for(var m=i,_=0,r="",u=!1;(_>0||m==i)&&m<=a;){var c=s.charAt(m);u||"{"!=c?u||"}"!=c?'"'==c&&"\\"!=r&&(u=!u):_--:_++,r=c,m++}console.log("Started at cursor="+i+", ended at cursor="+m+" with result following:"),console.log(s.substring(i,m));try{var t=JSON.parse(s.substring(i,m));return console.log("WPO: JSON re-parse successful"),t}catch(o){throw o}}}throw"WPO: could not parse the JSON"}jQuery(function(s){WP_Optimize_Smush=WP_Optimize_Smush()});var WP_Optimize_Smush=function(){function s(){var s=0==I('input[type="checkbox"]:checked',U).length;C.prop("disabled",s),T.prop("disabled",s)}function e(s,i){if(G){var a=I("#smush-information-modal-cancel-btn .smush-information");O("mark_all_as_uncompressed",{restore_backup:s?1:0,delete_only_backups_meta:i?1:0},function(i){if(G)return i.hasOwnProperty("error")?(y(I("#smush-information-modal"),I.unblockUI),I("#smush-information-modal .smush-information").text(i.error),void o()):void(i.completed?(y(I("#smush-information-modal"),I.unblockUI),I("#smush-information-modal .smush-information").text(i.message),o()):(a.text(i.message),e(s)))})}}function o(e){var e="undefined"==typeof e||e,o={use_cache:e};console.log("Loading information about uncompressed images."),P.html("..."),z.hide(),f(!0),O("get_ui_update",o,function(e){console.log("Information about uncompressed images loaded."),x(e,r),g(),f(!1),s()})}function a(){I("#wpo_smush_images_grid input:checked").each(function(){image={attachment_id:I(this).val(),blog_id:I(this).data("blog")},B.push(image)}),data={optimization_id:"smush",selected_images:B,smush_options:{compression_server:I("input[name='compression_server']:checked").val(),image_quality:I("#image_quality").val(),lossy_compression:I("#smush-lossy-compression").is(":checked"),back_up_original:I("#smush-backup-original").is(":checked"),preserve_exif:I("#smush-preserve-exif").is(":checked")}},u(),O("process_bulk_smush",data)}function n(){if(I("#wp-optimize-wrap").length){I("#wpo_smush_images_save_options_spinner").show().delay(3e3).fadeOut(),I("#enable_custom_compression").is(":checked")?(image_quality=I("#custom_compression_slider").val(),lossy_compression=image_quality<100):(image_quality=I("#enable_lossy_compression").is(":checked")?90:100,lossy_compression=image_quality<100);var s={compression_server:I("input[name='compression_server']:checked").val(),image_quality:image_quality,lossy_compression:lossy_compression,back_up_original:I("#smush-backup-original").is(":checked"),back_up_delete_after:I("#smush-backup-delete").is(":checked"),back_up_delete_after_days:I("#smush-backup-delete-days").val(),preserve_exif:I("#smush-preserve-exif").is(":checked"),autosmush:I("#smush-automatically").is(":checked"),show_smush_metabox:I("#smush-show-metabox").is(":checked")};O("update_smush_options",s,function(s){I("#wpo_smush_images_save_options_spinner").hide(),s.hasOwnProperty("saved")&&s.saved?(I("#wpo_smush_images_save_options_done").show().delay(3e3).fadeOut(),q.hide()):(I("#wpo_smush_images_save_options_fail").show().delay(3e3).fadeOut(),q.show())})}}function t(){X=!0,R++,seconds=R%60+""<10?"0"+R%60:R%60,minutes=parseInt(R/60)+""<10?"0"+parseInt(R/60):parseInt(R/60),I("#smush_stats_timer").text(minutes+":"+seconds),m(R)}function m(s){0==s%3&&_(),0==s%60&&O("process_pending_images",{},function(s){x(s,c)})}function _(s){data={update_ui:!0,use_cache:!1},O("get_ui_update",data,function(s){x(s,c)})}function r(s){if(U.html(""),s&&s.hasOwnProperty("unsmushed_images")){s.unsmushed_images,s.pending_tasks;0==s.unsmushed_images.length&&0==s.pending_tasks&&U.text(wposmush.all_images_compressed).wrapInner("
"),0!=s.pending_tasks&&z.show().find(".red").text(s.pending);var e="post.php?post=",o="&action=edit";for(blog_id in s.unsmushed_images)for(i in s.unsmushed_images[blog_id])s.unsmushed_images[blog_id].hasOwnProperty(i)&&(image=s.unsmushed_images[blog_id][i],d(image,blog_id,s.admin_urls[blog_id]+e+image.id+o))}}function u(){X||(y(I("#wpo_smush_images_information_container")),service=I('.compression_server input[type="radio"]:checked + label small').text(),I("#wpo_smush_images_information_server").html(service),I("#smush_stats_pending_images").html("..."),I("#smush_stats_completed_images").html("..."),I("#smush_stats_bytes_saved").html("..."),I("#smush_stats_percent_saved").html("..."),I("#smush_stats_timer").html("..."),Z=window.setInterval(t,1e3),f(!0))}function c(s){I("#smush_stats_pending_images").html(s.pending_tasks),I("#smush_stats_completed_images").html(s.completed_task_count),I("#smush_stats_bytes_saved").html(s.bytes_saved),I("#smush_stats_percent_saved").html(s.percent_saved),1==s.smush_complete&&setTimeout(l,1500)}function l(){data={update_ui:!0,use_cache:!1,image_list:B},O("get_ui_update",data,function(s){summary=s.session_stats,0!=s.completed_task_count&&(summary+=""+s.summary),p(summary)})}function p(s){F||(I("#summary-message").html(s),h(),y(I("#smush-complete-summary")),F=!0)}function h(){R=0,X=!1,F=!1,B=[],window.clearInterval(Z),f(!1)}function d(s,e,o){var i=["wpo_smush_",e,"_",s.id].join("");image_html='