console.log("tetcamMobileTool.js");var tettool_tetcam_mobile={init:function init(f,d){console.log(d.attr("itemtitle"));var c=get_tettool_param(d,"Nicht_schneiden");var a=get_tettool_param(d,"Label");if(a){$(".tetcamMobileOverlay",d).html(a)}d.attr("ignoreDblClick","ignoreDblClick");function e(h){var k=$("#mainPane");var m=k.offset();var j=d.offset();var l=j.left-m.left;var i=j.top-m.top;if(window.cssTransformScale&&window.cssTransformScale!=1){l=Math.round(l/window.cssTransformScale);i=Math.round(i/window.cssTransformScale)}var n={x:Math.round(l)+"px",y:Math.round(i)+"px",w:d.width()+"px",h:d.height()+"px",title:"tet.cam mobile photo",itemtype:"img",template_params:"tetLabel:tetcam."+d.attr("id"),descr_text:"",};if(username!="guest"){tetUploadDataUrl(h,"tetcam.jpg",n,undefined,function(){b()})}else{k.append('<div class="tetitem" itemtype="img" id="yy_'+random(10000000,99999999)+'"itemtitle="tet.cam mobile photo" inline="1" keepasprat="1" tetlabel="tetcam.'+d.attr("id")+'" style="top:'+n.y+"; left:"+n.x+"; width:"+n.w+"; height:"+n.h+';"><div class="tetitem_inner"><img class="tetitem_img " draggable="false" src="'+h+'"></div></div>');b()}}function b(){var h=$('.tetitem[tetLabel="tetcam.'+d.attr("id")+'"]');if(!h.length){return}$("<div class='tetcamMobileDeleteImageIcon'></div>").appendTo(h).on("click",function(){if(username!="guest"){tetDeleteTETitemAfterConfirm($(this).closest(".tetitem"),"Das Foto wirklich löschen?",function(){$(this).remove();reloadMainPane_afterChange_onlyOthers()})}else{var i=$(this).closest(".tetitem");if(confirm("Das Foto wirklich löschen?")){i.remove()}}})}function g(i){if(i.files&&i.files[0]){var h=new FileReader();h.onload=function(k){var j=new Image();j.src=k.target.result;j.onload=function(){if(!j.width){alert("Bild hat 0-Breite");return}if(!j.height){alert("Bild hat 0-Hoehe");return}var n=document.createElement("canvas");var x=n.getContext("2d");var o=d.width();var m=d.height();var p=1;if(!c){var u,s;var v,q;var t=j.width/j.height;var y=o/m;if(t>y){s=0;q=j.height;v=j.height*y;u=(j.width-v)/2}else{u=0;v=j.width;q=j.width/y;s=(j.height-q)/2}n.width=o;n.height=m;x.drawImage(j,u,s,v,q,0,0,o,m)}else{var l=j.width;var w=j.height;if(l>w){if(l>o){w*=o/l;l=o}}else{if(w>m){l*=m/w;w=m}}n.width=l;n.height=w;x.drawImage(j,0,0,l,w)}var r=n.toDataURL("image/jpeg");e(r)}};h.readAsDataURL(i.files[0])}}$("input",d).change(function(){g(this)}).click(function(){this.value=null});$(".tetcamMobileMediathek",d).on("click",function(){var h=$("input",d);if(h.attr("capture")){h.removeAttr("capture");$(this).addClass("active_on")}else{h.attr("capture","camera");$(this).removeClass("active_on")}h.trigger("click")});b()}};