function nothing(){}
function load_img(a){$("#img").remove();var b=document.createElement("img");b.src=a+"?"+Math.random(5);b.id="img";window.load_interval_timer=setInterval(function(){if(b.width>0&&b.height>0){try{clearInterval(window.load_interval_timer)}catch(c){}$(b).prependTo("#imgarea");var d=$("#imgarea").width()/b.width,e=$("#imgarea").height()/b.height;if(e<d)d=e;if(d>1)d=1;$(b).data("width",b.width).data("height",b.height).data("minp",d);zoom_to(d,200);$("#imgarea").get(0).scrollTop=0;$("#imgarea").get(0).scrollLeft=0;
$(b).bind("mousedown.move",function(f){if(!window.croping){var g=$("#imgarea").get(0),j=parseInt(f.clientX),k=parseInt(g.scrollLeft),m=parseInt(f.clientY),h=parseInt(g.scrollTop);$(this);$(document.body).bind("mousemove.img",function(i){var l=parseInt(i.clientX),n=parseInt(i.clientY);g.scrollTop=h-n+m;g.scrollLeft=k-l+j;i.preventDefault();return false}).bind("mouseup.img",function(){$(document.body).unbind(".img")});f.preventDefault();return false}})}},100)}
function crop_tracker_change(){var a=$(".jcrop-holder");if(!(a.length<=0)){a=a.get(0);var b=$(a.firstChild.firstChild.firstChild),c=$(a.firstChild);a=$("#img");var d=$("#imgarea").get(0);b.attr("src",a.attr("src"));b.css({left:-parseInt(d.scrollLeft)-parseInt(c.css("left")),top:-parseInt(d.scrollTop)-parseInt(c.css("top")),width:a.width(),height:a.height()});b=$("#img").data("p");b={x:Math.round((parseInt(d.scrollLeft)+parseInt(c.css("left")))/b),y:Math.round((parseInt(d.scrollTop)+parseInt(c.css("top")))/
b),w:Math.round(parseInt(c.width())/b),h:Math.round(parseInt(c.height())/b),src:$("#img").attr("src").replace(/\?[0-9\.]*$/ig,"")};if(b.x+b.w>a.data("width"))b.w=a.data("width")-b.x;if(b.y+b.h>a.data("height"))b.h=a.data("height")-b.y;if(b.w<=0)b.w=0;if(b.h<=0)b.h=0;$("#croped_width").val(b.w);$("#croped_height").val(b.h)}}
function update_crop(){if($(".jcrop-tracker").length>0){var a=parseInt($("#croped_width").val()),b=parseInt($("#croped_height").val()),c=$("#img").data("p");a*=c;b*=c;a>0&&b>0&&$("#transgif").data("Jcrop").setSelect([0,0,a,b])}}
function do_crop(){if(!($(".pop_box:visible").length>0)){window.croping=true;$("#img");var a=$(".jcrop-tracker");if(a.length>0){var b=$("#imgarea").get(0);a=a.parent().parent();if(!(a.width()<=0)){var c=$("#img").data("p");a={x:Math.round((parseInt(b.scrollLeft)+parseInt(a.css("left")))/c),y:Math.round((parseInt(b.scrollTop)+parseInt(a.css("top")))/c),w:Math.round(parseInt(a.width())/c),h:Math.round(parseInt(a.height())/c),src:$("#img").attr("src").replace(/\?[0-9\.]*$/ig,"")};if(a.x+a.w>$("#img").data("width"))a.w=
$("#img").data("width")-a.x;if(a.y+a.h>$("#img").data("height"))a.h=$("#img").data("height")-a.y;a.new_w=a.w;a.new_h=a.h;if(!(a.w<=0))if(!(a.h<=0)){$.post("?app=system&controller=attachment&action=crop_image",a,crop_callback,"json");$(document.body).trigger("mousedown.crop").unbind(".crop")}}}else{$('<div id="transgifwrapper"><img id="transgif" src="images/trans.png" /></div>').appendTo($("#imgarea").parent());window.croping=true;$("#crop_bar").fadeIn(200);a=$("#imgarea").offset();$("#transgifwrapper").css({height:$("#imgarea").height(),
width:$("#imgarea").width(),top:a.top,left:a.left}).find("img").css({height:$("#imgarea").height(),width:$("#imgarea").width()}).Jcrop({onChange:crop_tracker_change});setTimeout(function(){$(document.body).unbind(".crop").bind("mousedown.crop",function(d){if($(d.target).attr("rel")!="crop"){reset_topbt();$("#transgifwrapper").remove();d.preventDefault();d.stopPropagation();update_zoom();$(document.body).unbind(".crop");$("#crop_bar").hide();window.just_canceled_croping=true;setTimeout("window.just_canceled_croping = false;",
300);return false}});$(document.body).bind("keydown.crop",function(d){d.keyCode==13&&do_crop(d)})},300)}}}function crop_callback(a){reset_topbt();if(a.state){$(document.body).trigger("mousedown.crop");load_img_and_add_history(a.src)}else ct_alert(a.error,"error",false)}
function load_img_and_add_history(a){img_current++;for(img_history[img_current-1]=a;img_history.length>img_current;)img_history.pop();load_img(a);temporary_img_list.push(a);$("#prev_history").fadeTo(300,1);$("#next_history").fadeTo(300,0)}function update_zoom(){if(window.croping)window.croping=false;var a=parseInt($("#pointer").css("top"));if(a<=0){a=0;$("#pointer").css("top","0px")}if(a>=290){a=290;$("#pointer").css("top","290px")}a=290-a;zoom_to(a/290,0)}
function zoom_to(a,b){var c=$("#img");if(a>1)a=1;if(a<c.data("minp"))a=c.data("minp");b=parseInt(b);var d=c.data("width")*a,e=c.data("height")*a;if(window.adding_words){var f=d-c.width(),g=e-c.height();$(".word_img").each(function(){wimg=$(this);var j=f*wimg.data("px"),k=g*wimg.data("py");wimg.data("left",wimg.data("left")+j);wimg.data("top",wimg.data("top")+k);wimg.animate({width:wimg.data("width")*a,height:wimg.data("height")*a,top:wimg.data("top"),left:wimg.data("left")},b)})}c.animate({width:d,
height:e},b);$("#stick").height(e);$("#pointer").animate({top:290-a*290},b).html(parseInt(a*100)+"%");crop_tracker_change();c.data("p",a)}
function do_scale(){if(!($(".pop_box:visible").length>0)){dialog("choose",{title:"\u8c03\u6574\u56fe\u7247\u5927\u5c0f",dialog_id:"rescale_dialog",width:230,height:150,modal:false,type:"html",content:'<div style="margin:10px 20px;">\u5bbd\uff1a<input  class="dialog_input" size="4" type="text" rel="scale" id="new_w" onkeyup="check_wh(this)" value="'+$("#img").data("width")+'" />px&nbsp;&nbsp;\u9ad8\uff1a<input  class="dialog_input" size="4" type="text" rel="scale" id="new_h" onkeyup="check_wh(this)" value="'+
$("#img").data("height")+'" />px<br /><input style="border:0;" type="checkbox" id="baochibili" checked="checked" />\u4fdd\u6301\u6bd4\u4f8b</div>'},"scale_submit",reset_topbt);$("input[rel=scale]").keydown(function(a){a.keyCode==13&&scale_submit()})}}function check_wh(a){if($("#baochibili").is(":checked")){var b=$("#img"),c=b.data("width");b=b.data("height");$(a).attr("id")=="new_w"?$("#new_h").val(Math.round($(a).val()*b/c)):$("#new_w").val(Math.round($(a).val()*c/b))}}
function scale_submit(){var a=$("#img"),b=a.data("width");a=a.data("height");var c=parseInt($("#new_w").val()),d=parseInt($("#new_h").val());reset_topbt();if(!isNaN(c)&&!isNaN(d)&&c>0&&d>0){$.post("?app=system&controller=attachment&action=crop_image",{x:0,y:0,w:b,h:a,new_w:c,new_h:d,src:$("#img").attr("src").replace(/\?[0-9\.]*$/ig,"")},crop_callback,"json");$("#rescale_dialog").dialog("close")}else ct_alert("\u8f93\u5165\u9519\u8bef","error",false)}
function load_word_img(a,b){var c=document.createElement("img");c.src=a;c.className="word_img";if(b.left)c.style.left=b.left;if(b.top)c.style.top=b.top;if(b.zIndex)c.style.zIndex=b.zIndex;temporary_word_imgs.push(a);window.load_word_img_interval_timer=setInterval(function(){if(c.width>0&&c.height>0){try{clearInterval(window.load_word_img_interval_timer)}catch(d){}$(c).appendTo("#imgarea");$(c).data("width",c.width).data("height",c.height).data("vars",b);var e=$("#img").data("p");$(".selected").removeClass("selected");
$(c).height($(c).data("height")*e).width($(c).data("width")*e).addClass("selected");addword_imgs_indexes();$(c).bind("mousedown.move",function(f){$(".selected").removeClass("selected");$(c).addClass("selected");$("#add_word_bar").fadeIn(100);$(document.body).bind("click.add_word_select",function(h){if($(h.target).attr("rel")!="addword"){$("img.selected").removeClass("selected");$(document.body).unbind(".add_word_select");$("#add_word_bar").fadeOut(100)}});$("#imgarea").get(0);var g=parseInt(f.clientX),
j=parseInt($(c).css("left")),k=parseInt(f.clientY),m=parseInt($(c).css("top"));$(document.body).bind("mousemove.wordimg",function(h){var i=parseInt(h.clientX),l=parseInt(h.clientY);l=m+l-k;i=j+i-g;$(c).css("top",l);$(c).css("left",i);h.preventDefault();return false}).bind("mouseup.wordimg",function(){$(document.body).unbind(".wordimg");var h=$("#img"),i=parseInt($(c).css("left"))/h.width();h=parseInt($(c).css("top"))/h.height();$(c).data("px",i).data("py",h).data("left",parseInt($(c).css("left"))).data("top",
parseInt($(c).css("top")))});f.preventDefault();return false}).bind("dblclick",function(){add_word(this)}).mouseover(function(){$(c).addClass("hover")}).mouseout(function(){$(c).removeClass("hover")}).click(function(f){f.preventDefault();return false})}},100)}function cancel_add_word(){$(".word_img").remove();window.adding_words=false;$("#add_word_bar").fadeOut(300)}
function addword_put_backward(){var a=$("img.selected");if(a.length==1){addword_imgs_indexes();var b=parseInt(a.css("z-index"));if(b!=1){b--;var c=null;$("img.word_img").each(function(){if(this.style.zIndex==b)c=this});if(c){c.style.zIndex=a.css("z-index");a.css("z-index",b)}}}}
function addword_put_forward(){var a=$("img.selected");if(a.length==1){addword_imgs_indexes();var b=parseInt(a.css("z-index"));if(b!=$(".word_img").length){b++;var c=null;$("img.word_img").each(function(){if(this.style.zIndex==b)c=this});if(c){c.style.zIndex=a.css("z-index");a.css("z-index",b)}}}}
function addword_imgs_indexes(){var a=[];$(".word_img").each(function(){a.push({index:this.style.zIndex,img:this})});a.sort(function(c,d){return c.index-d.index});for(var b=0;b<a.length;b++)a[b].img.style.zIndex=b+1}function edit_addword(){var a=$("img.selected");a.length==1&&a.trigger("dblclick")}function delete_addword(){var a=$("img.selected");if(a.length==1){a.remove();addword_imgs_indexes()}}
function add_word_complete(a){var b=[],c=$("#img").data("p");$(".word_img").each(function(){var f={x:Math.round(parseInt($(this).css("left"))/c)+1,y:Math.round(parseInt($(this).css("top"))/c)+1,index:parseInt($(this).css("z-index")),src:$(this).attr("src")};b.push(f)});if(!(b.length<=0)){b.sort(function(f,g){return f.index-g.index});for(var d={bg:$("#img").attr("src").replace(/\?[0-9\.]*$/ig,"")},e=0;e<temporary_word_imgs.length;e++)d["temporary_word_imgs[]"]=temporary_word_imgs[e];for(e=0;e<b.length;e++){d["word_img["+
e+"][x]"]=b[e].x;d["word_img["+e+"][y]"]=b[e].y;d["word_img["+e+"][src]"]=b[e].src}$.post("?app=system&controller=attachment&action=add_word_do",d,function(f){if(f.state){load_img_and_add_history(f.src);cancel_add_word();a&&a(f.src)}else ct_alert(f.error,"error",false)},"json")}}
function add_word(a){if(!($(".pop_box:visible").length>0)){if(a==undefined)var b=false,c="\u6dfb\u52a0\u6587\u5b57",d={content:"",size:30,font:false,color:"#ffffff"};else{a=$(a);b=true;c="\u7f16\u8f91\u6587\u5b57";d=a.data("vars")}$("#add_word_dialog").remove();dialog("choose",{title:c,dialog_id:"add_word_dialog",width:350,height:200,modal:false,type:"html",content:'<div style="margin:10px 20px;line-height:30px;">\u6587\u5b57\uff1a<input style="width:220px;" class="dialog_input" type="text" rel="addword" id="addword_content"  value="'+
d.content+'" /><br />\u5927\u5c0f\uff1a<input size="3"  class="dialog_input"  type="text" rel="addword" id="addword_size" value="'+d.size+'" />pt&nbsp;&nbsp;\u989c\u8272\uff1a<input type="hidden" id="addword_color" value="'+d.color+'" /><img src="images/color.gif" alt="\u8272\u677f" height="16" width="16" id="choose_color" style="background-color:'+d.color+'" />&nbsp;\u5b57\u4f53\uff1a<select rel="addword"  id="addword_font">'+font_options+"</select><br /></div>"},add_word_submit=function(){var e=
{content:$("#addword_content").val(),size:parseInt($("#addword_size").val()),font:$("#addword_font").val(),color:$("#addword_color").val(),zIndex:false};if(e.content=="")$("#addword_content").css("border-color","red");else if(e.size<=0||isNaN(e.size))ct_alert("\u6587\u5b57\u5927\u5c0f\u5e94\u4e3a\u4e00\u4e2a\u6b63\u6574\u6570","error",false);else{if(b&&a){e.left=a.css("left");e.top=a.css("top");e.zIndex=a.css("z-index")}reset_topbt();$.post("?app=system&controller=attachment&action=create_words_image",
e,function(f){if(f.state){if(!e.zIndex){var g=1;$(".word_img").each(function(){if(parseInt(this.style.zIndex)>g)g=parseInt(this.style.zIndex)});e.zIndex=parseInt(g)+1}load_word_img(f.src,e);$("#add_word_dialog").dialog("close");window.adding_words=true;$("#add_word_bar").fadeIn(300);b&&a&&a.remove()}else ct_alert(f.error,"error",false)},"json")}},reset_topbt);$("#choose_color").click(function(){$(this).colorPicker({setColor:"#choose_color",setValue:"#addword_color"});$("#fy_ColorPicker").css("z-index",
"2000")});$("#addword_content").change(function(){$(this).css("border-color",this.value==""?"red":"")});b&&$("#addword_font").find("option").each(function(){if(this.value==d.font)this.selected=true});$("input[rel=addword]").keydown(function(e){e.keyCode==13&&add_word_submit()})}}
function all_submit(a){if(window.croping){ct_alert("\u8bf7\u5148\u5b8c\u6210\u56fe\u7247\u88c1\u526a\u64cd\u4f5c","error",false);$("[role=dialog]").find(".btn_area").find("button").attr("rel","crop")}else if(window.adding_words)add_word_complete(all_submit);else{var b=orig_img_src;a=a?a:$("#img").attr("src").replace(/\?[0-9\.]*$/ig,"");var c={orig_img:b,now_img:a};for(b=0;b<temporary_img_list.length;b++)c["temporary_img_list[]"]=temporary_img_list[b];$.post("?app=system&controller=attachment&action=edit_image_submit",
c,function(d){if(d)ct_alert(d,"error",false);else if(parent)if(parent.edit_image_done)parent.edit_image_done.call();else if(window.dialogCallback&&dialogCallback.ok)dialogCallback.ok(c);else window.getDialog&&getDialog().dialog("close")})}}function close_window(){if(parent)if(parent.edit_image_cancel)parent.edit_image_cancel.call();else if(window.dialogCallback&&dialogCallback.cancel)dialogCallback.cancel();else window.getDialog&&getDialog().dialog("close")}
function disable_topbt(a){$("[rel=topbt]").attr("disabled","disabled").addClass("button_noaction_style");$(a).attr("disabled","").removeClass("button_noaction_style")}function reset_topbt(){$("[rel=topbt]").attr("disabled","").removeClass("button_noaction_style")};
