(function(){var d=0,e,j;egg.thumbUploader=function(a){e=a||{};if(e.size&&typeof e.size=="number")e.size=[e.size,e.size];$.lightbox(egg.thumbUploader.getUploadContent,{absolute:true,className:"BH-popup",closeTrigger:egg.thumbUploader.close});$("#eggThumbBtnOk").click(function(){switch(d){case 2:var b=$("#cropperImage").attr("src"),f=j.getCropRect(),i=e.param||"";i+="&type="+b.substr(b.lastIndexOf(".")+1,3);i+="&size="+e.size[0];i+="&sizeW="+e.size[0]+"&sizeH="+e.size[1];i+="&x="+f.x+"&y="+f.y+"&w="+
f.w+"&h="+f.h;$("#ignoreCrop").attr("checked")&&(i+="&ignore=yes");e.saveImage&&(i+="&flag=1");if(i.indexOf("&")===0)i=i.substring(1);$.ajax({method:"POST",url:e.cropperAction,param:i,loading:function(){$("#eggThumbBtnOk").val("\u8655\u7406\u4e2d").attr("disabled",true)},success:function(n){$("#eggThumbBtnOk").val("\u78ba\u5b9a").attr("disabled",false);if(!egg.thumbUploader.error(n,$("#eggThumbMsg"))){e.success&&e.success.call(this,n);$.thumbUploader.close()}},fail:function(){$("#eggThumbMsg").html("\u8cc7\u6599\u67e5\u8a62\u932f\u8aa4!")}});
break;default:$("#eggThumbMsg").html("\u4e0a\u50b3\u4e2d\uff0c\u8acb\u7a0d\u5019......").show();$("#eggThumbBtnOk").val("\u8655\u7406\u4e2d").attr("disabled",true);if($("#eggThumbModeFile").attr("checked")){b=$("#eggThumbForm");b.attr("action",a.uploadAction);b.get(0).submit()}else $.ajax({method:"POST",param:"img="+encodeURI($("#eggThumbUrl").val()),url:a.uploadAction,loading:function(){$("#eggThumbBtnOk").val("\u8655\u7406\u4e2d").attr("disabled",true)},success:function(n){$("#eggThumbBtnOk").val("\u78ba\u5b9a").attr("disabled",
false);egg.thumbUploader.error(n,$("#eggThumbMsg"))||egg.thumbUploader.cropping(n)}})}});$("#eggThumbModeUrl").click(function(){d=0;$("#eggThumbFile").hide();$("#eggThumbTruth").hide();$("#eggThumbUrlBlock").show();$("#eggThumbMsg").hide();$.lightbox.refresh()});$("#eggThumbModeFile").click(function(){d=0;$("#eggThumbUrl").val("");$("#eggThumbUrlImage").hide();$("#eggThumbTruth").hide();$("#eggThumbFile").show();$("#eggThumbUrlBlock").hide();$("#eggThumbMsg").hide();$.lightbox.refresh()});$("#eggThumbModeTruth").click(function(){d=
0;$("#eggThumbFile").hide();$("#eggThumbUrlImage").hide();$("#eggThumbUrlBlock").hide();$("#eggThumbMsg").html("\u53d6\u5f97\u8cc7\u6599\u4e2d\uff0c\u8acb\u7a0d\u5f8c...").show();egg.thumbUploader.getTruthList(1);$.lightbox.refresh()});$("#eggThumbUrl").keyup(function(){$("#eggThumbUrlImage").attr("src",$("#eggThumbUrl").val())}).focus(function(){$("#eggThumbUrl").get(0).select()});$("#eggThumbUrlImage").load(function(){$("#eggThumbUrlImage").show().attr("eggThumbStatus","loaded").resizeImage(300);
$("#eggThumbMsg").hide();$.lightbox.refresh()});$("#eggThumbUrlImage").error(function(){d=0;$("#eggThumbUrlImage").hide().attr("eggThumbStatus","error");$("#eggThumbMsg").html("\u627e\u4e0d\u5230\u5716\u7247\uff0c\u53ef\u80fd\u662f\u5716\u6a94\u683c\u5f0f\u4e0d\u7b26\u6216\u7db2\u5740\u6709\u8aa4\u3002").show();$.lightbox.refresh()})};egg.method.resizeImage=function(a){this.removeAttr("width").removeAttr("height");var b=this.attr("offsetWidth"),f=this.attr("offsetHeight");this.attr({originalWidth:b,
originalHeight:f});if(b>a){f=parseInt(a/b*f,10);b=a}this.attr({width:b,height:f});return this};egg.thumbUploader.error=function(a,b){var f=true;switch(a){case "ERR_NO_LOGIN":b.html("\u60a8\u5c1a\u672a\u767b\u5165!");break;case "ERR_WRONG_TYPE":b.html("\u9019\u662f\u4e0d\u652f\u63f4\u7684\u6a94\u6848\u985e\u578b\uff0c\u8acb\u91cd\u65b0\u78ba\u8a8d\u3002");break;case "ERR_NO_IMAGE":b.html("\u627e\u4e0d\u5230\u5716\u7247!");break;case "ERR_CREATE_FAIL":b.html("\u88c1\u5207\u5716\u7247\u5931\u6557!");
break;case "ERR_OUT_OF_LIMIT":case "ERR_OUT_OF_SIZE":b.html("\u8acb\u78ba\u8a8d\u5716\u7247\u6a94\u6848\u5927\u5c0f\u53ca\u5bec\u9ad8\u662f\u5426\u904e\u5927\u3002");break;case "ERR_URL_INCORRECT":b.html("\u8acb\u78ba\u8a8d\u60a8\u8f38\u5165\u7684\u7db2\u5740\u662f\u5426\u6b63\u78ba");break;default:f=false}return f};egg.thumbUploader.uploadComplete=function(a){if(!egg.thumbUploader.error(a,$("#eggThumbMsg"))){egg.thumbUploader.cropping(a);d=2;$("#eggThumbMsg").hide()}};egg.thumbUploader.cropping=
function(a){$(".BH-popintxt").html(function(){return egg.thumbUploader.getCropperContent(a)});$("#cropperImage").load(function(){$("#cropperImage").show().resizeImage(300);$.lightbox.refresh();j=$("#cropperImage").imageCropper({preview:$("#previewImage").get(0),previewSize:e.size,fixed:e.fixed});d=2});$("#btnPreviousStep").click(function(){$.thumbUploader.close();$.thumbUploader(e);d=0});$("#ignoreCrop").click(function(){if($("#ignoreCrop").attr("checked")){$("#cropperImage");var b=$("#cropperImage").attr("originalWidth"),
f=$("#cropperImage").attr("originalHeight");if(b>e.size[0]){f=parseInt(e.size[0]/b*f,10);b=e.size[0]}if(f>e.size[1]){b=parseInt(e.size[1]/f*b,10);f=e.size[1]}var i=parseInt(e.size[0]/2-b/2,10),n=parseInt(e.size[1]/2-f/2,10);$("#eggCropperPreviewImage").css({left:i+"px",top:n+"px",width:b+"px",height:f+"px"});$("#eggCropperMask").hide();$("#eggCropperDragDiv").hide();$("#eggCropperResizer").hide()}else{$("#eggCropperMask").show();$("#eggCropperDragDiv").show();$("#eggCropperResizer").show();j.refreshPreview()}})};
egg.thumbUploader.getUploadContent=function(){var a="";a+='<p class="BH-poptitle">\u4e0a\u50b3\u7e2e\u5716</p>\n';a+='<div class="BH-popintxt">\n';a+='<table cellspacing="0" cellpadding="0">\n';a+="<tr>\n";a+='  <td valign="middle"><label><input checked="checked" type="radio" name="eggThumbMode" id="eggThumbModeFile">\u7531\u500b\u4eba\u96fb\u8166\u4e0a\u50b3</label></td>\n';a+='  <td valign="middle"><label><input type="radio" name="eggThumbMode" id="eggThumbModeTruth">\u7531\u5c0f\u5c4b\u5716\u7247\u7a7a\u9593</label></td>\n';
a+='  <td valign="middle"><label><input type="radio" name="eggThumbMode" id="eggThumbModeUrl">\u7531\u7db2\u8def\u5716\u7247\u64f7\u53d6</label></td>\n';a+="</tr>\n";a+="<tr>\n";a+='  <td colspan="3" align="left" height="45">\n';a+='    <form id="eggThumbForm" method="post" enctype="multipart/form-data" target="eggThumbIframe">\n';a+='      <input size="30" name="eggThumbFile" id="eggThumbFile" type="file" />\n';a+="    </form>\n";a+='    <iframe name="eggThumbIframe" id="eggThumbIframe" style="display:none;"></iframe>\n';
a+='    <div style="display:none;" id="eggThumbUrlBlock">\u5716\u7247\u7db2\u5740\uff1a<input size="30" id="eggThumbUrl" type="text" /><br />\n';a+='      <img id="eggThumbUrlImage" style="display:none;" />\n';a+="    </div>\n";a+='    <div style="display:none;height:330px;width:610px;overflow:auto" id="eggThumbTruth"></div>\n';a+='    <span id="eggThumbMsg" style="display:none;color:red;"></span>';a+="  </td>\n";a+="</tr>\n";a+="<tr>\n";a+='  <td colspan="3">\u652f\u63f4JPG\u3001GIF \u6216 PNG \u6a94\u6848\u3002(\u8acb\u6ce8\u610f\uff0c\u5716\u7247\u5167\u5bb9\u53d7\u7ad9\u898f\u9650\u5236\u3002)</td>\n';
a+="</tr>\n";a+="</table>\n";a+="</div>\n";a+='<p class="BH-popbtns">\n';a+='<input id="eggThumbBtnOk" style="width:100px;" type="button" value="\u78ba\u5b9a" />\n';a+='<input style="width:100px;" type="button" value="\u96e2\u958b" onclick="$.thumbUploader.close();" />\n';a+="</p>";return a};egg.thumbUploader.getCropperContent=function(a){var b="";b+='<table cellspacing="0" cellpadding="0" class="BH-poptb1">\n';b+="<tr>\n";b+='  <td colspan="2" valign="middle"><input type="button" value="\u4e0a\u4e00\u6b65" id="btnPreviousStep" /> <span id="eggThumbMsg" style="color:red;"></span></td>\n';
b+="</tr>\n";b+="<tr>\n";b+='<td valign="top">\u9078\u53d6\u60a8\u60f3\u8981\u88c1\u5207\u7684\u5340\u584a\uff1a<br /><img style="display:none;" src="'+a+"?t="+(new Date).getTime()+'" id="cropperImage" /></td>\n';b+='<td valign="top" style="padding-left:5px;">\u9810\u89bd\uff1a<br /><div id="previewImage" style="width:120px;height:120px;" ></div></td>\n';b+="</tr>\n";b+="<tr>\n";b+='  <td colspan="2" valign="middle"><label><input type="checkbox" id="ignoreCrop" value="yes" />\u6211\u4e0d\u9700\u8981\u88c1\u5207\u5716\u7247</label></td>\n';
b+="</tr>\n";b+="</table>\n";return b};egg.thumbUploader.close=function(){$.lightbox.close();d=0;try{document.body.removeChild($("#eggCropperMask").get(0));document.body.removeChild($("#eggCropperDragDiv").get(0));document.body.removeChild($("#eggCropperResizer").get(0))}catch(a){}};egg.thumbUploader.getTruthList=function(a){$.ajax({url:"/ajax/listtruthimage2.php",param:"p="+a,success:function(b){if(b=="ERR_NOLOGIN")$("#eggThumbMsg").html("\u8acb\u5148\u767b\u5165").show();else{$("#eggThumbMsg").hide();
if(a==1)egg("#eggThumbTruth").html(b).show();else{var f=egg("#eggThumbTruth"+a).get(0),i=f.parentNode;egg(document.createElement("div")).html(b).appendTo(i);i.removeChild(f);egg("#eggThumbTruth").get(0).scrollTop=egg("#eggThumbTruth").get(0).scrollHeight}}$.lightbox.refresh()},fail:function(){$("#eggThumbMsg").html("\u767c\u751f\u932f\u8aa4, \u8acb\u7a0d\u5f8c\u518d\u8a66\u4e00\u6b21").show();$.lightbox.refresh()}});$.lightbox.refresh()}})();
(function(){egg.extend.imageCropper=function(d){d=d||{};d.previewSize=d.previewSize||[120,120];var e=false,j=false,a=this.image=$(this.get(0)),b=a.attr("offsetWidth"),f=a.attr("offsetHeight");this.moveDrag=function(c){c=window.event||c;if(c.button===($.browser.ie?1:0)){e=true;var g=c.clientY;a.attr({cropperLeft:c.clientX-$("#eggCropperDragDiv").attr("offsetLeft"),cropperTop:g-$("#eggCropperDragDiv").attr("offsetTop")});$.event.preventDefault(c)}};this.moveDrop=function(c){c=window.event||c;e=false;
$.event.preventDefault(c)};this.moveDragging=function(c){if(e){c=window.event||c;var g=$("#eggCropperDragDiv"),h=a.pos(),k=c.clientY,o=c.clientX-a.attr("cropperLeft");k=k-a.attr("cropperTop");var l=a.attr("offsetWidth"),m=a.attr("offsetHeight"),p=g.attr("offsetWidth"),r=g.attr("offsetHeight"),s=g.attr("offsetLeft"),t=g.attr("offsetTop");if(o<h.x)o=h.x;if(k<h.y)k=h.y;l=h.x+l-p;m=h.y+m-r;if(o>l)o=l;if(k>m)k=m;g.css({left:o+"px",top:k+"px"});$("#eggCropperDragImage").css({left:"-"+(s-h.x)+"px",top:"-"+
(t-h.y)+"px"});$("#eggCropperResizer").css({left:s+p-3+"px",top:t+r-3+"px"});q();$.event.stop(c);$.event.preventDefault(c)}};var i=function(c){if(j){c=window.event||c;var g=$("#eggCropperDragDiv"),h=a.pos(),k=a.attr("offsetWidth"),o=a.attr("offsetHeight"),l=c.clientX-h.x,m=c.clientY-h.y;c=g.attr("offsetLeft")-h.x;h=g.attr("offsetTop")-h.y;l=l-c;m=m-h;var p=d.fixed||d.fixed===undefined&&d.previewSize[0]==d.previewSize[1];if(p)m=parseInt(l/d.previewSize[0]*d.previewSize[1],10);if(l<1){if(p)return;l=
1}if(m<1){if(p)return;m=1}if(l+c>k){if(p)return;l=k-c}if(m+h>o){if(p)return;m=o-h}g.css({width:l+"px",height:m+"px"});$("#eggCropperDragContainer").css({width:l+"px",height:m+"px"});$("#eggCropperResizer").css({left:g.attr("offsetLeft")+l-5+"px",top:g.attr("offsetTop")+m-5+"px"});$("#eggCropperCover").css({left:$("#eggCropperResizer").attr("offsetLeft")-75+"px",top:$("#eggCropperResizer").attr("offsetTop")-75+"px"});q()}},n=function(c){c=window.event||c;j=false;try{document.body.removeChild($("#eggCropperCover").get(0))}catch(g){}$.event.preventDefault(c)};
this.resizeDrag=function(c){c=window.event||c;j=true;var g=document.createElement("div");$(g).attr({id:"eggCropperCover",unselectable:"on"}).css({backgroundColor:"red",width:"150px",height:"150px",position:"absolute",left:$("#eggCropperResizer").attr("offsetLeft")-75+"px",top:$("#eggCropperResizer").attr("offsetTop")-75+"px",zIndex:104,cursor:"se-resize"}).mousemove(i).mouseup(n).mouseout(n).opacity(0);document.body.appendChild(g);$.event.preventDefault(c)};egg.imageCropper.create.call(this,d);var q=
this.refreshPreview=function(){var c=$("#eggCropperPreviewImage"),g=$("#eggCropperDragDiv"),h=d.previewSize[0]/g.attr("offsetWidth"),k=d.previewSize[1]/g.attr("offsetHeight"),o=a.pos();c.css({left:"-"+parseInt((g.attr("offsetLeft")-o.x)*h,10)+"px",top:"-"+parseInt((g.attr("offsetTop")-o.y)*k,10)+"px"});c.css({width:parseInt(b*h,10)+"px",height:parseInt(f*k,10)+"px"})};if(d&&d.preview){$(d.preview).css({backgroundColor:"white",width:d.previewSize[0]+"px",height:d.previewSize[1]+"px",overflow:"hidden",
position:"relative"});$(d.preview).html('<img id="eggCropperPreviewImage" src='+a.attr("src")+' style="position:absolute;left:0px;top:0px;" />');q()}this.getCropRect=function(){var c=$("#eggCropperDragDiv"),g=a.attr("originalWidth")/a.attr("offsetWidth"),h=a.pos(),k=parseInt((c.attr("offsetLeft")-h.x)*g,10);h=parseInt((c.attr("offsetTop")-h.y)*g,10);var o=parseInt(c.attr("offsetWidth")*g,10);c=parseInt(c.attr("offsetHeight")*g,10);return{x:k,y:h,w:o,h:c}};return this};egg.imageCropper={create:function(d){var e=
this.image.pos(),j=this.image.attr("offsetWidth"),a=this.image.attr("offsetHeight"),b=document.createElement("div");$(b).attr("id","eggCropperMask").css({width:j+"px",height:a+"px",position:"absolute",left:e.x+"px",top:e.y+"px",backgroundColor:"#333333",zIndex:101}).opacity(0.7);var f=d.previewSize[0];d=d.previewSize[1];if(j<f){d=parseInt(d*(j/f),10);f=j}if(a<d){f=parseInt(f*(a/d),10);d=a}var i=e.x+parseInt(j/2-f/2,10),n=e.y+parseInt(a/2-d/2,10),q=document.createElement("div");$(q).attr({id:"eggCropperDragDiv",
unselectable:"on"}).css({"-moz-user-select":"none",width:f+"px",height:d+"px",position:"absolute",left:i+"px",top:n+"px",zIndex:102}).html('<div id="eggCropperDragContainer"><img id="eggCropperDragImage" /></div>');document.body.appendChild(b);document.body.appendChild(q);$("#eggCropperDragContainer").css({width:f+"px",height:d+"px",position:"relative",overflow:"hidden"});$("#eggCropperDragImage").attr("src",this.image.attr("src")).css({width:j+"px",height:a+"px",position:"absolute",left:"-"+(i-e.x)+
"px",top:"-"+(n-e.y)+"px",cursor:"move"}).mousedown(this.moveDrag).mouseup(this.moveDrop).mouseout(this.moveDrop).mousemove(this.moveDragging);e=$("#eggCropperDragDiv");j=document.createElement("div");$(j).attr({id:"eggCropperResizer",unselectable:"on"}).css({width:"12px",height:"12px",position:"absolute",left:e.attr("offsetLeft")+e.attr("offsetWidth")-3+"px",top:e.attr("offsetTop")+e.attr("offsetHeight")-3+"px",backgroundColor:"#FFFFCF",border:"solid 1px black",fontSize:"1pt",zIndex:103,cursor:"se-resize"}).mousedown(this.resizeDrag);
document.body.appendChild(j)}}})();

