var $j=jQuery.noConflict();var bwbpsActiveGallery=0;var displayedGalleries="";var bwbpsUploadStatus=false;var bwbpsSelectedImages;var bwbpsStopResizing=false;var bwbpsAllImport=0;$j.fn.tagName=function(){return this.get(0).tagName};$j(document).ready(function(){$j("#bwbps_loading").ajaxStart(function(){$j(this).show()}).ajaxComplete(function(){$j(this).hide();if(bwbpsUploadStatus==false){$j("#bwbps_submitBtn").removeAttr("disabled");$j("#bwbps_imgcaptionInput").removeAttr("disabled");$j("#bwbps_message").html("Image upload failed. Your image may have been too large or there may have been another problem. Please reload the page and try again.")}bwbpsUploadStatus=false});$j(".bwbps_uploadform").submit(function(){$j("#bwbps_message").html("");bwbpsAjaxLoadImage(this);return false});$j(".init_radio").attr("checked","checked");if($j("#bwbps_gen_settingsform").val()=="1"){bwbpsAddPSSettingsMassUpdateActions()}$j(".bwbps-post-cat-form").attr("multiple","multiple")});function bwbpsSaveFavorite(d,c){var a={};a.action="favoriteimage";a.image_id=d;a._wpnonce=c;try{$j("#ps_savemsg").show()}catch(b){}if(jQuery(".bwbps-fav-"+d).hasClass("bwbps-fav-0")){jQuery(".bwbps-fav-"+d).removeClass("bwbps-fav-0");jQuery(".bwbps-fav-"+d).addClass("bwbps-fav-1")}else{jQuery(".bwbps-fav-"+d).removeClass("bwbps-fav-1");jQuery(".bwbps-fav-"+d).addClass("bwbps-fav-0")}$j.ajax({type:"POST",url:bwbpsAjaxRateImage,data:a,dataType:"json",success:function(e){bwbpsFavoriteSuccess(e,d)}});return false}function bwbpsFavoriteSuccess(a,b){if(a==-1){alert("Security failed: nonce.");return}if(a.status==1){if(jQuery(".bwbps-fav-"+b).hasClass("bwbps-fav-0")){jQuery(".bwbps-fav-"+b).removeClass("bwbps-fav-0");jQuery(".bwbps-fav-"+b).addClass("bwbps-fav-1")}}else{if(jQuery(".bwbps-fav-"+b).hasClass("bwbps-fav-1")){jQuery(".bwbps-fav-"+b).removeClass("bwbps-fav-1");jQuery(".bwbps-fav-"+b).addClass("bwbps-fav-0")}}}function bwbpsAjaxLoadImage(c){var b=c.id;b=b.replace("bwbps_uploadform","");$j("#"+b+"bwbps_imgcaption").val($j("#"+b+"bwbps_imgcaptionInput").val());$j("#"+b+"bwbps_result").html("");$j("#"+b+"bwbps_message").html("");$j("#"+b+"bwbps_previewpost").html("");$j("#"+b+"bwbps_loading").show();$j("#"+b+"bwbps_loading").ajaxComplete(function(){$j(this).hide()});var a={beforeSubmit:function(){if(!bwbpsVerifyUploadRequest(b)){$j("#"+b+"bwbps_loading").hide();return false}else{return true}},success:function(d,e){bwbpsUploadSuccess(d,e,b)},failure:function(){alert("failed")},url:bwbpsAjaxUpload,iframe:true,dataType:"json"};$j(c).ajaxSubmit(a);return false}$j(window).bind("load",psSetGalleryHts);function psSetGalleryHts(){if(displayedGalleries==""){return}var c=displayedGalleries.split("|");var a=0;var b=c.length;for(a=0;a<b;a++){if(c[a]!=""){bwbps_equalHeight($j(".psgal_"+c[a]))}}}function bwbpsVerifyUploadRequest(a){if(!bwbpsVerifyFileFilled(a)){$j("#"+a+"bwbps_message").html("<b>VALIDATION ERROR: Please select a file.</b>");$j("#"+a+"bwbps_submitBtn").removeAttr("disabled");$j("#"+a+"bwbps_imgcaptionInput").removeAttr("disabled");return false}$j("#"+a+"bwbps_submitBtn").attr("disabled","disabled");$j("#"+a+"bwbps_imgcaptionInput").attr("disabled","disabled");$j("#"+a+"bwbps_result").html("");return true}function bwbpsVerifyFileFilled(a){if($j("#"+a+"bwbps_allownoimg").val()==1){return true}var b=$j("#"+a+"bwbps_uploadform :input:radio[name=bwbps_filetype]:checked").val();var c=false;switch(Number(b)){case 0:c=$j("#"+a+"bwbps_uploadfile").val();break;case 1:c=$j("#"+a+"bwbps_uploadurl").val();if(c){$j("#"+a+"bwbps_uploadfile").val("")}break;case 2:c=$j("#"+a+"bwbps_uploaddl").val();if(c){$j("#"+a+"bwbps_uploadfile").val("")}break;case 3:c=$j("#"+a+"bwbps_uploadyt").val();break;case 4:c=$j("#"+a+"bwbps_uploadvid").val();break;case 5:c=$j("#"+a+"bwbps_uploadfile2").val();break;case 6:c=$j("#"+a+"bwbps_uploadurl2").val();if(c){$j("#"+a+"bwbps_uploadfile2").val("")}break;default:c=true;break}if(c){return true}else{return false}}function bwbpsUploadSuccess(g,c,f){if(bwbpsAlternateUploadFunction(g,c,f)){return false}$j("#"+f+"bwbps_submitBtn").removeAttr("disabled");$j("#"+f+"bwbps_imgcaptionInput").removeAttr("disabled");bwbpsUploadStatus=true;if(c=="success"){if(g==-1){alert("security failure: nonce");$j("#"+f+"bwbps_message").html("<span class='error'>Upload failed due to invalid authorization.  Please reload this page and try again.</span>");if(g.special_msg){$j("#"+f+"bwbps_message").append("<p>"+unescape(g.special_msg)+"</p>")}return false}if(g.succeed=="false"){$j("#"+f+"bwbps_message").html(g.message);if(g.special_msg){$j("#"+f+"bwbps_message").append("<p id='bwbps_special_msg'>"+unescape(g.special_msg)+"</p>")}return false}if(g.db_saved>0){if(g.thumb_fullurl){$j("#"+f+"bwbps_result").html('<img src="'+g.thumb_fullurl+'" />')}else{$j("#"+f+"bwbps_result").html('<img src="'+bwbpsThumbsURL+g.img+'" />')}if(g.message==undefined){g.message=""}else{g.message="<br/>"+g.message}$j("#"+f+"bwbps_message").html("<b>Upload successful!</b>"+g.message);$j(".bwbps_reset").val("");var b;if($j("#bwbps_stdgal_"+g.gallery_id).length==0){b=$j("<div></div>");b.attr("id","bwbps_galcont_"+g.gallery_id).attr("class","");$j("<h2></h2>").html("Added Images").appendTo(b);var e=$j("<table></table>");var h=$j("<tr></tr>");h.appendTo(e);var a=$j("<td></td>");a.appendTo(h);var d=$j("<ul></ul>").attr("class","bwbps_gallery bwbps_custom_add").attr("id","bwbps_stdgal_"+g.gallery_id);d.appendTo(a);e.appendTo(b);b.insertAfter("#bwbpsInsertBox_"+g.gallery_id)}var k=$j("<li></li>").attr("class","ps_newimage psgal_"+g.gallery_id).appendTo("#bwbps_stdgal_"+g.gallery_id);if(g.li_width>0){k.css("width",g.li_width+"%")}else{k.css("margin","15px")}if(Number(g.thumb_height)){var j=Number(g.thumb_height)+15}if(j=="NaN"||j<16){j=125}if($j("#bwbps_stdgal_"+g.gallery_id).hasClass("bwbps_custom_add")){k.css("height",j+"px")}var m;if($j.browser.msie){m=$j("<div></div>").css("width",g.thumb_width)}else{m=$j("<div></div>").css("width",g.thumb_width).css("margin","auto")}var i;if(g.thumb_fullurl){i=$j("<a></a>").attr("href",g.image_fullurl).attr("rel",g.imgrel);$j('<img src="'+g.thumb_fullurl+'" />').appendTo(i)}else{i=$j("<a></a>").attr("href",bwbpsImagesURL+g.img).attr("rel",g.imgrel);$j('<img src="'+bwbpsThumbsURL+g.img+'" />').appendTo(i)}if(g.show_imgcaption>0){$j("<br />").appendTo(i);$j("<span>"+g.image_caption+"</span>").attr("class","bwbps_caption").appendTo(i)}i.appendTo(m);m.appendTo(k);bwbps_equalHeight($j(".psgal_"+g.gallery_id));k.append("&nbsp;");if(g.special_msg){var l="";if(g.preview_id){l="<a href='/?p="+g.preview_id+"&preview=true' target='_blank'>Preview</a>"}$j("#"+f+"bwbps_previewpost").append("<p>"+l+unescape(g.special_msg)+"</p>")}}else{$j("#"+f+"bwbps_message").html("Image not saved: "+g.error);if(g.special_msg){$j("#"+f+"bwbps_message").append("<p>"+unescape(g.special_msg)+"</p>")}}}else{$j("#"+f+"bwbps_message").html("Unknown error!")}}function bwbpsShowPhotoUpload(c,b,a){if(a==null){a=""}bwbpsActiveGallery=c;$j("#"+a+"bwbps_galleryid").val(c);$j("#"+a+"bwbps_post_id").val(b);$j("#"+a+"bwbps_submitBtn").removeAttr("disabled")}function bwbpsShowPhotoUploadNoThickbox(c,b,a){bwbpsActiveGallery=c;if(!a){a=""}$j("#"+a+"bwbps_galleryid").val(c);$j("#"+a+"bwbps_post_id").val(b);$j("#"+a+"bwbps-formcont").hide();$j("#"+a+"bwbps-formcont").appendTo("#bwbpsFormSpace_"+c);$j("#bwbpsFormSpace_"+c).show();$j("#"+a+"bwbps-formcont").show("slow");$j("#"+a+"bwbps_submitBtn").removeAttr("disabled")}function bwbpsHideUploadForm(b,a){if(!b){b=""}if(a==null){a=""}$j("#"+a+"bwbps-formcont").hide("slow");$j("#bwbpsFormSpace_"+b).hide("slow")}function bwbpsSwitchUploadField(c,b,a){if(b==null){b=""}if(a==null){a=""}$j("."+a+"bwbps_uploadspans"+b).hide();$j("#"+c).fadeIn("slow")}function bwbpsToggleFormAlwaysVisible(){if($j("#bwbps_use_thickbox").attr("checked")){$j("#bwbps_formviz").fadeOut("slow")}else{$j("#bwbps_formviz").fadeIn("slow")}}function bwbps_equalHeight(a){tallest=0;a.each(function(){thisHeight=$j(this).height();if(thisHeight>tallest){tallest=thisHeight}});a.height(tallest)}function bwbpsToggleDivHeight(a,b){if($j("#"+a).css("height")==b){$j("#"+a).css("height","auto")}else{$j("#"+a).css("height",b)}}function bwbpsToggleCheckboxes(b,a){$j("input:checkbox."+b).attr("checked",a)}function bwbpsModerateImage(n,j,q){var k=parseInt(""+j);var s=false;var i="";var d=parseInt(""+q);var r=" (image id: "+k+")";var o=jQuery("#ps_mod_send_msg").attr("checked")?1:0;var g="";var b=true;switch(n){case"publishpost":s=n;i="publish post: "+d;break;case"remove":s=n;i="remove this image from gallery (leaves Media Library images in tact) ";break;case"bury":s="delete";i="delete this image (Note: will only 'remove' if more than one record uses image. Will delete images from Media Gallery if 'delete' is used. Use 'remove' to leave Media Gallery images in tact.) ";if(o&&!confirm("Is Rejection Moderation Message correct?\n\n "+jQuery("#ps_mod_reject_msg").val())){return}else{if(o){g=jQuery("#ps_mod_reject_msg").val()}}break;case"approve":s=n;i="approve this image ";if(o&&!confirm("Is Approve Moderation Message correct?\n\n "+jQuery("#ps_mod_approve_msg").val())){return}else{if(o){g=jQuery("#ps_mod_approve_msg").val()}}break;case"review":s=n;i="mark this image as reviewed ";break;case"savecaption":s=n;i="save image data ";break;case"saveall":s="savecaption";i="save image data ";b=false;break}if(!s){alert("Invalid action.");return false}if(b){if(!confirm("Do you want to "+i+r+")?")){return false}}var e=$j("#_moderate_nonce").val();var l="";var t="";var m="";var p="";var c="";var h="";var a=0;if(s=="savecaption"){l=$j("#imgcaption_"+k).val();t=$j("#imgurl_"+k).val();h=$j("#imgseq_"+k).val();m=$j("#imgtags_"+k).val();p=$j("#imgmeta_"+k).val();c=$j("#fileurl_"+k).val();a=$j("#image_post_id_"+k).val()}try{$j("#ps_savemsg").show()}catch(f){}$j.ajax({type:"POST",url:bwbpsAjaxURL,data:{action:s,image_id:k,_ajax_nonce:e,image_caption:l,image_url:t,image_tags:m,meta_data:p,file_url:c,seq:h,post_id:d,image_post_id:a,mod_msg:g,send_msg:o},dataType:"json",success:function(u){bwbpsModerateSuccess(u,k)}});return false}function bwbpsModerateSuccess(c,a){jQuery(".bwbps_save_flds_"+a).attr("src",bwbpsPhotoSmashURL+"images/disk.png");try{$j("#ps_savemsg").hide()}catch(b){}if(c==-1){alert("Failed due to security: invalid nonce");$j("#psmod_"+a).html("fail: security");return false}if(c.status=="false"||c.status==0){$j("#psmod_"+a).html("update: fail");return false}else{switch(c.action){case"published":$j("#psimg_pubpost"+a).html("published");$j("#psimg_pubpost"+a).addClass("ps-moderate");break;default:$j("#psmod_"+a).html("");$j("#psmodmsg_"+a).html(c.action);if(c.deleted=="deleted"){$j("#psimage_"+a).html("")}$j("#psimg_"+a).removeClass("ps-moderate");break}return false}}jQuery.fn.bwbpsFade=function(f){var j=(f&&f.constructor==String)?{start:f}:f||{};var h=jQuery.bwbpsFade.defaults;var e=j.interval||h.interval;var b=j.attr||h.attr;var g={linear:function(d,i,a,k){return parseInt(d+(k/a)*(i-d))},sinusoidal:function(d,i,a,k){return parseInt(d+Math.sin(((k/a)*90)*(Math.PI/180))*(i-d))},exponential:function(d,i,a,k){return parseInt(d+(Math.pow(k/a,2))*(i-d))}};var c=(j.iterator&&j.iterator.constructor==Function)?j.iterator:g[j.iterator]||g[h.iterator]||g.linear;if(h.iterator&&h.iterator.constructor==Function){c=h.iterator}return this.each(function(){if(!this.highlighting){this.highlighting={}}var i=(this.highlighting[b])?this.highlighting[b].end:jQuery.bwbpsFade.getBaseValue(this,b)||[255,255,255];var k=jQuery.bwbpsFade.getRGB(j.start||j.colour||j.color||h.start||[255,255,128]);var a=jQuery.speed(j.speed||h.speed);var d=j["final"]||(this.highlighting[b]&&this.highlighting[b].orig)?this.highlighting[b].orig:jQuery.curCSS(this,b);if(j.end||h.end){d=jQuery.bwbpsFade.asRGBString(i=jQuery.bwbpsFade.getRGB(j.end||h.end))}if(typeof j["final"]!="undefined"){d=j["final"]}if(this.highlighting[b]&&this.highlighting[b].timer){window.clearInterval(this.highlighting[b].timer)}this.highlighting[b]={steps:((a.duration)/e),interval:e,currentStep:0,start:k,end:i,orig:d,attr:b};jQuery.bwbpsFade(this,b,j.complete,c)})};jQuery.bwbpsFade=function(d,b,f,c){d.highlighting[b].timer=window.setInterval(function(){var e=c(d.highlighting[b].start[0],d.highlighting[b].end[0],d.highlighting[b].steps,d.highlighting[b].currentStep);var a=c(d.highlighting[b].start[1],d.highlighting[b].end[1],d.highlighting[b].steps,d.highlighting[b].currentStep);var g=c(d.highlighting[b].start[2],d.highlighting[b].end[2],d.highlighting[b].steps,d.highlighting[b].currentStep);jQuery(d).css(b,jQuery.bwbpsFade.asRGBString([e,a,g]));if(d.highlighting[b].currentStep++>=d.highlighting[b].steps){jQuery(d).css(b,d.highlighting[b].orig||"");window.clearInterval(d.highlighting[b].timer);d.highlighting[b]=null;if(f&&f.constructor==Function){f.call(d)}}},d.highlighting[b].interval)};jQuery.bwbpsFade.defaults={start:[255,255,128],interval:50,speed:400,attr:"backgroundColor"};jQuery.bwbpsFade.getRGB=function(e,b){var a;if(e&&e.constructor==Array&&e.length==3){return e}if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(e)){return[parseInt(a[1]),parseInt(a[2]),parseInt(a[3])]}else{if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(e)){return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55]}else{if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(e)){return[parseInt("0x"+a[1]),parseInt("0x"+a[2]),parseInt("0x"+a[3])]}else{if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(e)){return[parseInt("0x"+a[1]+a[1]),parseInt("0x"+a[2]+a[2]),parseInt("0x"+a[3]+a[3])]}else{return jQuery.bwbpsFade.checkColorName(e)||b||null}}}}};jQuery.bwbpsFade.asRGBString=function(b){return"rgb("+b.join(",")+")"};jQuery.bwbpsFade.getBaseValue=function(h,d,c){var g,f;c=c||false;f=d=d||jQuery.bwbpsFade.defaults.attr;do{g=jQuery(h).css(f||"backgroundColor");if((g!=""&&g!="transparent")||(h.tagName.toLowerCase()=="body")||(!c&&h.highlighting&&h.highlighting[d]&&h.highlighting[d].end)){break}f=false}while(h=h.parentNode);if(!c&&h.highlighting&&h.highlighting[d]&&h.highlighting[d].end){g=h.highlighting[d].end}if(g==undefined||g==""||g=="transparent"){g=[255,255,255]}return jQuery.bwbpsFade.getRGB(g)};jQuery.bwbpsFade.checkColorName=function(a){if(!a){return null}switch(a.replace(/^\s*|\s*$/g,"").toLowerCase()){case"aqua":return[0,255,255];case"black":return[0,0,0];case"blue":return[0,0,255];case"fuchsia":return[255,0,255];case"gray":return[128,128,128];case"green":return[0,128,0];case"lime":return[0,255,0];case"maroon":return[128,0,0];case"navy":return[0,0,128];case"olive":return[128,128,0];case"purple":return[128,0,128];case"red":return[255,0,0];case"silver":return[192,192,192];case"teal":return[0,128,128];case"white":return[255,255,255];case"yellow":return[255,255,0]}};
