var a; function uploadform_onupload(b,c){var d=null;switch(b){case 1:d=document.getElementById("upload-submit-file");if(!document.getElementById("upload-imagefile").value)if(!c){alert("Please choose a file to upload!");return false}break;case 2:d=document.getElementById("upload-submit-url");if(b=document.getElementById("upload-imageurl"))if(!b.value||b.value.length<=5||b.value=="http://"){alert("Please enter an URL!");return false}break}if(d)d.disabled=true;window.setTimeout(delegate(TPEditorUI,"showLoadIndicator",true), 150);return true}function uploadform_enableUI(b){document.getElementById("upload-submit-file").disabled=!b;document.getElementById("upload-submit-url").disabled=!b}function applyeffect(b,c){if(b){var d=document.getElementById("effect-cascade2");if(d){d.action="/photo-effects/"+b;annotateUI.storeToForm("effect-cascade2");if(c)d.elements.src.value="";d.submit();return false}}} function addEvent(b,c,d){if(b.addEventListener){b.addEventListener(c,d,false);return true}else return b.attachEvent?b.attachEvent("on"+c,d):false}function delegate(b,c,d,e,g){return function(){b[c].call(b,d,e,g)}}function delegate_event(b,c){return function(d){b[c].call(b,d)}}function delegate_event1(b,c,d,e,g){return function(f){b[c].call(b,f,d,e,g)}}function setStyle(b,c){if(b.style&&b.style.setAttribute)b.style.cssText=b.style.cssText+";"+c;else b.setAttribute("style",b.style.cssText+";"+c)} var nzindex=0;function bringElementToTop(b){if(b&&b.style)if(!(b.style.zIndex>=nzindex)){nzindex++;b.style.zIndex=nzindex}}function new_xmlhttp(){var b=null;try{b=new XMLHttpRequest}catch(c){try{b=new ActiveXObject("Msxml2.XMLHTTP")}catch(d){try{b=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){wsq_request=null}}}return b}function rfalse(){return false} function urlencode_form(b){for(var c="",d=0;d<b.elements.length;d++)if(b.elements[d]&&b.elements[d].name)if(!((b.elements[d].type=="checkbox"||b.elements[d].type=="radio")&&!b.elements[d].checked)){var e=b.elements[d].value;c+=b.elements[d].name+"=";c+=encodeURIComponent(e);c+="&"}return c}function setInputImage(b){if(wsEffect){var c=document.getElementById("set-input-image-form");if(c){c.elements.src.value=b;c.submit()}}} function submitFilterSettings(){document.getElementById("filter-settings").submit()}function TTTOOLTIP_onmousemove(b){TTTOOLTIP.pos(b)} var TTTOOLTIP={_id:"tt",_top:6,_left:24,_tt:null,_h:0,_timerHide:0,_timerHideTimeout:120,show:function(b){TTTOOLTIP.cancelTimerHide();if(TTTOOLTIP._tt==null){if(!(TTTOOLTIP._tt=document.createElement("div")))return;TTTOOLTIP._tt.setAttribute("id",TTTOOLTIP._id);TTTOOLTIP._tt.style.display="none";var c=document.getElementsByTagName("body")[0];c.insertBefore(TTTOOLTIP._tt,c.firstChild)}TTTOOLTIP._tt.innerHTML=b;document.onmousemove=TTTOOLTIP_onmousemove;TTTOOLTIP._tt.onmousemove=delegate(TTTOOLTIP, "cancelTimerHide")},pos:function(b){if(TTTOOLTIP._tt){var c=0,d=0;if(!b)b=window.event;if(b.pageX||b.pageY){c=b.pageX;d=b.pageY}else if(b.clientX||b.clientY){c=b.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;d=b.clientY+document.body.scrollTop+document.documentElement.scrollTop}setStyle(TTTOOLTIP._tt,"top:"+(d-TTTOOLTIP._top)+"px;left:"+(c+TTTOOLTIP._left)+"px;display:block;")}},hide_do:function(){if(TTTOOLTIP._tt){document.onmousemove=null;TTTOOLTIP.cancelTimerHide();TTTOOLTIP._tt.style.display= "none"}},hide:function(){TTTOOLTIP.cancelTimerHide();TTTOOLTIP._timerHide=window.setTimeout(delegate(TTTOOLTIP,"hide_do"),TTTOOLTIP._timerHideTimeout)},cancelTimerHide:function(){TTTOOLTIP._timerHide&&window.clearTimeout(TTTOOLTIP._timerHide)}},ddp_reqobj=new_xmlhttp(),ddp_active="";function ddp_filters(b){ddp_toggle("/ddp/filters/"+b,true)}function ddp_workingset(b,c){ddp_toggle("/queryWorkingset?wsid="+b+"&effect="+c,false)} function ddp_toggle(b,c){if(b==ddp_active){var d=document.getElementById("editorUI-ddp-anchor");if(!d)return;if(d.style.display=="block"){d.style.display="none";return}else if(c){d.style.display="block";return}}ddp_active=b;c=ddp_reqobj;TPEditorUI.showLoadIndicator(true);c.open("GET",b,true);c.onreadystatechange=ddp_onreadystatechange;c.send(null);return false}function ddp_close(){var b=document.getElementById("editorUI-ddp-anchor");if(b)b.style.display="none"} function ddp_onreadystatechange(){var b=ddp_reqobj;if(!(!b||b.readyState!=4)){TPEditorUI.showLoadIndicator(false);if(b.status==200){var c=document.getElementById("editorUI-ddp-anchor");if(c){c.innerHTML=b.responseText;c.style.display="block"}}}} function activateTab(b,c,d,e,g,f,h){for(var i=document.getElementById("tab-"+b),k=i.parentNode.firstChild;k;){k.className="tab-inactive";k=k.nextSibling}i.className="tab-active";b=document.getElementById("tabpanel-"+b);for(i=b.parentNode.firstChild;i;){i.className="tabpanel-inactive";i=i.nextSibling}b.className="tabpanel-active";c&&c(b,d,e,g,f,h);ImageSelectBox.install()}var RH_NORTH=1,RH_EAST=2,RH_SOUTH=4,RH_WEST=8,RH_DRAG=-1; function CrRHelper(b){this._roffB=this._roffR=this._roffT=this._roffL=this._roffY=this._roffX=this._flags=0;this._element=null;this._idPrefix=b?b:"crUI-";this._knobHeight=this._knobWidth=10;this._idCregion=this._idPrefix+"cregion";this._idContainer=this._idPrefix+"container";this._idElement=null;this._asratio=this._flags=this._startH=this._startW=0;this._minHeight=this._minWidth=20}a=CrRHelper.prototype; a.flags2str=function(b){var c="";if(b&RH_NORTH)c+="n";if(b&RH_SOUTH)c+="s";if(b&RH_WEST)c+="w";if(b&RH_EAST)c+="e";return c};a.createKnob=function(b,c){var d=this.flags2str(c),e=document.createElement("div");e.setAttribute("id",this._idPrefix+"knob-"+d);e.className="cropUI-resizehandle";e.style.cursor=d+"-resize";e.style.width=this._knobWidth+"px";e.style.height=this._knobHeight+"px";e.onmousedown=delegate_event1(this,"onmousedown",c);b.appendChild(e)}; a.createOverlay=function(b,c){var d=document.createElement("div");d.setAttribute("id",this._idPrefix+"cropUI-overlay-"+c);d.className="cropUI-overlay";d.style.zIndex=1E4;b.appendChild(d)}; a.attach=function(b,c){if(!b)return false;this._isCrop=c;this._flags=0;this._element=b;this._idElement=b.id;this._startW=b.offsetWidth;this._startH=b.offsetHeight;this._aspectratio=this._startH/this._startW;this._keepAspectratio=1;var d=document.createElement("div");d.setAttribute("id",this._idContainer);d.style.position="relative";d.style.width=this._startW+"px";d.style.height=this._startH+"px";d.onselectstart=rfalse;d.onmousedown=rfalse;d.onclick=function(){return true};var e=document.createElement("div"); e.setAttribute("id",this._idCregion);e.className="crUI-cregion";e.style.position="absolute";e.style.left="0px";e.style.top="0px";e.onselectstart=rfalse;e.style.width=this._startW+"px";e.style.height=this._startH+"px";if(c){e.onmousedown=delegate_event1(this,"onmousedown",RH_DRAG);e.style.cursor="move"}this.createKnob(e,RH_NORTH|RH_WEST);this.createKnob(e,RH_NORTH);this.createKnob(e,RH_NORTH|RH_EAST);this.createKnob(e,RH_EAST);this.createKnob(e,RH_SOUTH|RH_EAST);this.createKnob(e,RH_SOUTH);this.createKnob(e, RH_SOUTH|RH_WEST);this.createKnob(e,RH_WEST);if(this._isCrop){this.createOverlay(d,"n");this.createOverlay(d,"e");this.createOverlay(d,"s");this.createOverlay(d,"w")}var g=b.parentNode,f=b.nextSibling;d.appendChild(b);d.appendChild(e);g.insertBefore(d,f);e.style.display="block";d.style.display="block";if(c){b=parseInt(this._startW*0.2);c=parseInt(this._startH*0.2);this.resize(b,c,this._startW-2*b,this._startH-2*c)}else this.resize(0,0,this._startW,this._startH)}; a.detach=function(){var b=document.getElementById(this._idElement),c=document.getElementById(this._idContainer);c.parentNode.insertBefore(b,c);c.parentNode.removeChild(c)};a.reset=function(){this.resize(0,0,this._startW,this._startH)}; a.onmousedown=function(b,c){if(this._flags)return false;if(!c)return false;var d=0,e=0;if(!b)b=window.event;if(b.pageX||b.pageY){d=b.pageX;e=b.pageY}else if(b.clientX||b.clientY){d=b.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;e=b.clientY+document.body.scrollTop+document.documentElement.scrollTop}this._flags=c;document.onmousemove=delegate_event(this,"onmousemove");document.onmouseup=delegate_event(this,"onmouseup");this._roffX=d;this._roffY=e;b=document.getElementById(this._idCregion); this._roffL=parseInt(b.style.left);this._roffT=parseInt(b.style.top);c=b.offsetHeight;this._roffR=this._roffL+b.offsetWidth;this._roffB=this._roffT+c;c=document.getElementById(this._idContainer);if(this._flags!=RH_DRAG)c.style.cursor=b.style.cursor=this.flags2str(this._flags)+"-resize";return false}; a.onmouseup=function(){if(!this._flags)return false;this._flags=0;document.onmousemove=null;document.onmouseup=null;var b=document.getElementById(this._idContainer),c=document.getElementById(this._idCregion);b.style.cursor="auto";c.style.cursor=this._isCrop?"move":"auto";return false}; a.onmousemove=function(b){var c=this._flags;if(!c)return false;var d=0,e=0;if(!b)b=window.event;if(b.pageX||b.pageY){d=b.pageX;e=b.pageY}else if(b.clientX||b.clientY){d=b.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;e=b.clientY+document.body.scrollTop+document.documentElement.scrollTop}var g=document.getElementById(this._idCregion),f=document.getElementById(this._idContainer),h=parseInt(g.style.left);b=parseInt(g.style.top);var i=h+parseInt(g.style.width);g=b+parseInt(g.style.height); var k=i-h,j=g-b;d=d-this._roffX;e=e-this._roffY;if(this._isCrop&&this._flags==RH_DRAG){h=this._roffL+d;if(h<0)h=0;if(h+k>f.offsetWidth)h=f.offsetWidth-k;i=h+k;b=this._roffT+e;if(b<0)b=0;if(b+j>f.offsetHeight)b=f.offsetHeight-j;g=b+j}else{if(c&RH_NORTH)b=this._roffT+e;if(c&RH_EAST)i=this._roffR+d;if(c&RH_SOUTH)g=this._roffB+e;if(c&RH_WEST)h=this._roffL+d;if(g<b){c=this._flags=c&(RH_EAST|RH_WEST)|(c&RH_NORTH?RH_SOUTH:RH_NORTH);e=this._roffB;this._roffB=this._roffT;this._roffT=e}if(i<h){this._flags= c&(RH_NORTH|RH_SOUTH)|(c&RH_WEST?RH_EAST:RH_WEST);e=this._roffR;this._roffR=this._roffL;this._roffL=e}}b=Math.max(Math.min(b,f.offsetHeight),0);h=Math.max(Math.min(h,f.offsetWidth),0);g=Math.max(Math.min(g,f.offsetHeight),0);i=Math.max(Math.min(i,f.offsetWidth),0);if(i-h<30)return false;if(g-b<30)return false;c=Math.min(h,i);h=Math.max(h,i);i=Math.min(b,g);b=Math.max(b,g);this.resize(c,i,h-c,b-i);return false}; a.resize=function(b,c,d,e){b=b;var g=c;c=d;var f=e;if(!this._isCrop){if(this._keepAspectratio){b=f<0?-1:1;f=c*this._aspectratio;f=parseInt(f+0.5);f=Math.abs(f)*b}g=document.getElementById(this._idContainer);b=g.offsetWidth*0.5-c*0.5;g=g.offsetHeight*0.5-f*0.5;b=parseInt(b);parseInt(g);g=0;c=parseInt(c);f=parseInt(f)}var h=document.getElementById(this._idCregion);setStyle(h,"left:"+b+"px;top:"+g+"px;width:"+c+"px;height:"+f+"px;");d=1/(this._startW/d);e=1/(this._startH/e);this._onresize&&this._onresize(this, b,g,c,f,d,e);this.positionKnobs()}; a.positionKnobs=function(){var b=document.getElementById(this._idCregion),c=parseInt(b.style.width),d=parseInt(b.style.height),e=this._knobWidth,g=this._knobHeight,f=null,h=0,i=0,k=this._idPrefix+"knob-",j="visibility:"+(this._keepAspectratio?"hidden;":"visible;");if(f=document.getElementById(k+"nw")){i=h=0;setStyle(f,"left:"+h+"px;top:"+i+"px;")}if(f=document.getElementById(k+"n")){h=parseInt(c*0.5-e*0.5);i=0;setStyle(f,"left:"+h+"px;top:"+i+"px;"+j)}if(f=document.getElementById(k+"ne")){h=c-e;i= 0;setStyle(f,"left:"+h+"px;top:"+i+"px;")}if(f=document.getElementById(k+"e")){h=c-e;i=parseInt(d*0.5-g*0.5);setStyle(f,"left:"+h+"px;top:"+i+"px;"+j)}if(f=document.getElementById(k+"se")){h=c-e;i=d-g;setStyle(f,"left:"+h+"px;top:"+i+"px;")}if(f=document.getElementById(k+"s")){h=parseInt(c*0.5-e*0.5);i=d-g;setStyle(f,"left:"+h+"px;top:"+i+"px;"+j)}if(f=document.getElementById(k+"sw")){h=0;i=d-g;setStyle(f,"left:"+h+"px;top:"+i+"px;")}if(f=document.getElementById(k+"w")){h=0;i=parseInt(d*0.5-g*0.5); setStyle(f,"left:"+h+"px;top:"+i+"px;"+j)}if(this._isCrop){e=null;g=this._startW;f=this._startH;h=parseInt(b.style.left);b=parseInt(b.style.top);e=document.getElementById(this._idPrefix+"cropUI-overlay-n");setStyle(e,"left:0px;top:0px;width:"+g+"px;height:"+b+"px;");e=document.getElementById(this._idPrefix+"cropUI-overlay-e");setStyle(e,"left:"+(h+c)+"px;top:"+b+"px;width:"+(g-(h+c))+"px;height:"+d+"px;");e=document.getElementById(this._idPrefix+"cropUI-overlay-s");setStyle(e,"left:0px;top:"+(b+d)+ "px;width:"+g+"px;height:"+(f-(b+d))+"px;");e=document.getElementById(this._idPrefix+"cropUI-overlay-w");setStyle(e,"left:0px;top:"+b+"px;width:"+h+"px;height:"+d+"px;")}};a.keepAspectratio=function(b){this._keepAspectratio=b;this.positionKnobs()};a.getWidth=function(){var b=document.getElementById(this._idCregion);return parseInt(b.style.width)};a.getHeight=function(){var b=document.getElementById(this._idCregion);return parseInt(b.style.height)}; a.dimensions=function(){var b=document.getElementById(this._idCregion),c={};c.left=parseInt(b.style.left);c.top=parseInt(b.style.top);c.right=c.left+parseInt(b.style.width);c.bottom=c.top+parseInt(b.style.height);return c}; var resizeUI={_prefix:"crUI-",_containerId:"textlayer",_cropregionId:"crUI-cropregion",_resizer:null,_originalWidth:0,_originalHeight:0,onresize:function(b,c,d,e,g){b=document.getElementById("rendered-image");setStyle(b,"position:absolute;left:"+c+"px;top:"+d+"px;width:"+e+"px;height:"+g+"px")},startResize:function(){TPEditorUI.cancelUI();resizeUI.showDropdown(true,false);resizeUI._resizer=new CrRHelper;resizeUI._resizer._onresize=function(b,c,d,e,g,f,h){resizeUI.onresize(b,c,d,e,g,f,h)};resizeUI._resizer.attach(document.getElementById("image-container"), false);annotateUI.showTextlayer(false)},startCrop:function(){TPEditorUI.cancelUI();resizeUI.showDropdown(true,true);resizeUI._resizer=new CrRHelper;resizeUI._resizer.attach(document.getElementById("image-container"),true);annotateUI.showTextlayer(false)},showDropdown:function(b,c){var d=document.getElementById("toolbar-dropdown");if(!d)return false;if(b){b=document.getElementById("rendered-image");resizeUI._originalWidth=b.offsetWidth;resizeUI._originalHeight=b.offsetHeight;b="resizeUI.applyResize()"; var e="Resize Picture",g="";if(c){b="resizeUI.applyCrop()";e="Crop Picture"}else{c=1;for(var f="",h=0;h<4;h++){var i=parseInt(resizeUI._originalWidth*c),k=parseInt(resizeUI._originalHeight*c);if(i<30||k<30)break;if(f)f+=" | ";var j="";switch(c){case 1:j="Original Size";break;case 0.75:j="3/4";break;case 0.5:j="Half Size";break;case 0.25:j="1/4";break}f+='<a href="#" onclick="resizeUI.setSize('+i+","+k+');return false"><em>'+j+"</em> ("+i+"x"+k+")</a>";c-=0.25}g+="<div>";g+='<span class="resizebar-input"><input type="checkbox" id="crUI-keep-aspect-ratio" checked value="1" onclick="resizeUI.keepAspectratio(this.checked)"><label class="checkbox" for="crUI-keep-aspect-ratio">Keep aspect ratio</label></span>'; g+='<span class="resizebar-sizes">'+f+'<input type="checkbox" style="visibility:hidden;"</span>';g+="</div>"}g+='<div class="resizebar-confirm"><button class="confirm" onclick="'+b+';return false">'+e+'</button> <button class="cancel" onclick="resizeUI.cancelUI();return false">Cancel</button></div>';g+='<div class="clear"></div>';d.innerHTML=g;d.style.display="block"}else{d.innerHTML="";d.style.display="none"}},setSize:function(b,c){resizeUI._resizer&&resizeUI._resizer.resize(0,0,b,c);return false}, keepAspectratio:function(b){resizeUI._resizer&&resizeUI._resizer.keepAspectratio(b)},applyResize:function(){annotateUI.storeToForm("effect-cascade2");var b=document.getElementById("effect-cascade2");b.action="/photo-effects/resize";this._resizer.dimensions();var c=create_input_hidden(b,"efp_transform_resizeW"),d=create_input_hidden(b,"efp_transform_resizeH");c.value=resizeUI._resizer.getWidth();d.value=resizeUI._resizer.getHeight();b.submit()},applyCrop:function(){annotateUI.storeToForm("effect-cascade2"); var b=document.getElementById("effect-cascade2");b.action="/photo-effects/crop";var c=this._resizer.dimensions(),d=create_input_hidden(b,"efp_transform_cropL"),e=create_input_hidden(b,"efp_transform_cropT"),g=create_input_hidden(b,"efp_transform_cropR"),f=create_input_hidden(b,"efp_transform_cropB");d.value=c.left;e.value=c.top;g.value=c.right;f.value=c.bottom;b.submit()},cancelUI:function(){if(resizeUI._resizer){resizeUI._resizer.reset();resizeUI._resizer.detach();resizeUI._resizer=null;resizeUI.showDropdown(false); document.getElementById("rendered-image").style.position="static";annotateUI.resizeTextLayer(0,0,resizeUI._originalWidth,resizeUI._originalHeight,1,1);annotateUI.showTextlayer(true)}}};function chiRegion_show(b,c,d,e,g){chiRegion.show(b,c,d,e,g)} var chiRegion={_formID:"filter-settings-form",_formElementRegion:"efp_cropinput",_formElementMode:"efp_chir_mode",_idModeSelect:"chiRegion-mode",_resizer:null,show:function(b,c,d,e,g){TPEditorUI.cancelUI();if(chiRegion._resizer)return false;var f=document.getElementById(chiRegion._formID);if(!f)return false;var h=parseInt(d*0.2),i=parseInt(e*0.2),k=d-2*h,j=e-2*i,l=f.elements[chiRegion._formElementRegion];if(l&&l.value)if((l=l.value.split(","))&&l.length==4){h=parseInt(l[0]);i=parseInt(l[1]);k=parseInt(l[2])- h;j=parseInt(l[3])-i}f=f.elements[chiRegion._formElementMode].value;l="";l='<div id="cropUI">'+('<div class="cropUI-controls">'+('<div>Mode: <select id="'+chiRegion._idModeSelect+'"><option value="1"'+(f==1?" selected":"")+'>Use selected region as input</option><option value="2"'+(f==2?" selected":"")+(g?"":" disabled")+'>Filter selected region</option><option value="3"'+(f==3?" selected":"")+(g?"":" disabled")+">Filter region not selected</option></select></div>")+' <button onClick="chiRegion.submit(); return false" class="confirm">Use Selection</button> <button onclick="chiRegion.cancel(); return false" class="cancel">Cancel / Use entire image</button></div>')+ '<div id="cropUI-container" style="width:'+d+"px;height:"+e+'px;"><img src="'+c+'" id="fsdlg-baseimage" width="'+d+'" height="'+e+'" alt="">';l+="</div></div>";b.innerHTML=l;chiRegion._resizer=new CrRHelper("choose-input-region");chiRegion._resizer.attach(document.getElementById("fsdlg-baseimage"),true);chiRegion._resizer.resize(h,i,k,j);return false},cancelUI:function(){if(chiRegion._resizer){chiRegion._resizer.detach();chiRegion._resizer=null}},submit:function(){if(chiRegion._resizer){var b=chiRegion._resizer.dimensions(), c=document.getElementById(chiRegion._formID),d=document.getElementById(chiRegion._idModeSelect);c.elements[chiRegion._formElementRegion].value=(new Array(b.left,b.top,b.right,b.bottom)).join(",");c.elements[chiRegion._formElementMode].value=d.value;annotateUI.storeToForm(chiRegion._formID);c.submit()}},cancel:function(){var b=document.getElementById(chiRegion._formID);b.elements[chiRegion._formElementRegion].value="";b.elements[chiRegion._formElementMode].value=0;annotateUI.storeToForm(chiRegion._formID); b.submit()}},DragHandler={_oElem:null,_container:null,ondragend:null,ondragbegin:null,attach:function(b,c){if(b){DragHandler._container=c;b.onmousedown=DragHandler._dragBegin;b=b.parentNode;b.dragBegin=new Function;b.drag=new Function;b.dragEnd=new Function;return b}},_dragBegin:function(b){var c=DragHandler._oElem=this.parentNode;if(c){DragHandler.ondragbegin&&DragHandler.ondragbegin.call();if(isNaN(parseInt(c.style.left)))c.style.left="0px";if(isNaN(parseInt(c.style.top)))c.style.top="0px";var d= parseInt(c.style.left),e=parseInt(c.style.top);b=b?b:window.event;c.mouseX=b.clientX;c.mouseY=b.clientY;bringElementToTop(c);c.dragBegin(c,d,e);document.onmousemove=DragHandler._drag;document.onmouseup=DragHandler._dragEnd;return false}},_drag:function(b){var c=DragHandler._oElem;if(!c)return false;var d=parseInt(c.style.left),e=parseInt(c.style.top);b=b?b:window.event;var g=d+b.clientX-c.mouseX,f=e+b.clientY-c.mouseY,h=0,i=0;if(DragHandler._container){var k=DragHandler._container.offsetWidth-c.offsetWidth; if(g>k){h=k-g;g=k}k=DragHandler._container.offsetHeight-c.offsetHeight;if(f>k){i=k-f;f=k}if(g<0){h=-g;g=0}if(f<0){i=-f;f=0}}c.style.left=g+"px";c.style.top=f+"px";c.mouseX=b.clientX+h;c.mouseY=b.clientY+i;c.drag(c,d+h,e+i);return false},_dragEnd:function(){var b=DragHandler._oElem;if(b){var c=parseInt(b.style.left),d=parseInt(b.style.top);b.dragEnd(b,c,d)}document.onmousemove=null;document.onmouseup=null;DragHandler._oElem=null;DragHandler.ondragend&&DragHandler.ondragend.call(b)}},annotateUI={_nextID:1, _activeElement:null,_controlsTimerId:null,_textNodes:[],_countTextElements:0,_stateTimerId:0,_stateNotification:new_xmlhttp(),_stateFetcher:new_xmlhttp(),createTextElement:function(b,c){TPEditorUI.cancelUI();var d=document.getElementById("textlayer"),e="text-node"+annotateUI._nextID;annotateUI._nextID++;var g=b?b:annotateUI._fetchTextProperties("addtext");if(!g)return false;var f=annotateUI._imgURL(g),h=e+"-img";f='<div class="sticker" id="'+e+'" onmouseover="annotateUI.showControls(\''+e+"')\" onmouseout=\"annotateUI.hideControls('"+ e+'\')" style="z-index:'+annotateUI._nextID+';"><div id="'+e+'-controls" class="sticker-controls"><a href="#" onClick="javascript:annotateUI.removeElement(\''+e+'\');return false;">X</a></div><img src="'+f+'" id="'+h+'" onClick="annotateUI._setActiveElement(\''+e+"');\" ></div>";var i=document.createElement("div");i.innerHTML=f;d.appendChild(i);if(f=document.getElementById(e))f.annotateUI_textProperties=g;if(!DragHandler.ondragbegin)DragHandler.ondragbegin=delegate(annotateUI,"_clear_state_timer"); if(!DragHandler.ondragend)DragHandler.ondragend=delegate(annotateUI,"_update_state");DragHandler.attach(document.getElementById(h),d);annotateUI._setActiveElement(e);document.getElementById("annotateUI-text").value="";if(b){f.style.left=b.x+"px";f.style.top=b.y+"px"}else{f.style.left=parseInt(d.offsetWidth*0.3)+"px";f.style.top=parseInt(d.offsetHeight*0.5)+"px"}c||annotateUI._update_state();return false},editTextElement:function(){if(!annotateUI._activeElement)return false;var b=document.getElementById(annotateUI._activeElement); if(!b)return false;var c=annotateUI._fetchTextProperties("addtext");if(!c)return false;document.getElementById(annotateUI._activeElement+"-img").src=annotateUI._imgURL(b.annotateUI_textProperties=c);annotateUI._update_state()},_imgURL:function(b){return"/sticker/text?tl_text0="+encodeURIComponent(b.text)+"&tl_font0="+encodeURIComponent(b.font)+"&tl_size0="+encodeURIComponent(b.size)+"&tl_color0="+encodeURIComponent(b.color)+"&tl_extra0="+encodeURIComponent(b.extra)+"&tl_bold0="+encodeURIComponent(b.bold)+ "&tl_italic0="+encodeURIComponent(b.italic)+"&tl_count=1"},_fetchTextProperties:function(){var b={},c=null;if(c=document.getElementById("annotateUI-text"))b.text=c.value;if(!b.text)return null;if(c=document.getElementById("annotateUI-font"))b.font=c.value;if(c=document.getElementById("annotateUI-fontsize"))b.size=c.value;if(c=document.getElementById("annotateUI-color"))b.color=c.value;if(c=document.getElementById("annotateUI-extra"))b.extra=c.value;if(c=document.getElementById("annotateUI-bold"))b.bold= c.value;if(c=document.getElementById("annotateUI-italic"))b.italic=c.value;return b},_setActiveElement:function(b){if(annotateUI._activeElement=b){if(b=document.getElementById(b)){bringElementToTop(b);b=b.annotateUI_textProperties;document.getElementById("annotateUI-text").value=b.text;document.getElementById("annotateUI-fontsize").value=b.size;document.getElementById("annotateUI-font").value=b.font;document.getElementById("annotateUI-extra").value=b.extra;document.getElementById("annotateUI-button-edit").style.display= "inline";var c=document.getElementById("annotateUI-color");if(c.color&&c.color.fromString)c.color.fromString(b.color);else c.value=b.color}}else document.getElementById("annotateUI-button-edit").style.display="none"},removeElement:function(b){if(b=document.getElementById(b)){b.parentNode.removeChild(b);annotateUI._setActiveElement(null);annotateUI._update_state()}},showControls:function(b){if(b=document.getElementById(b+"-controls")){if(annotateUI._controlsTimerId){clearInterval(annotateUI._controlsTimerId); annotateUI._controlsTimerId=0}b.style.display="block"}},hideControls:function(b){if(b=document.getElementById(b+"-controls"))b.style.display="none"},storeToForm:function(b){b=document.getElementById(b);for(var c=document.getElementById("textlayer"),d=c.firstChild,e=0,g;d;){var f=d.firstChild;if(f&&f.annotateUI_textProperties){g=create_input_hidden(b,"tl_text"+e);g.value=f.annotateUI_textProperties.text;g=create_input_hidden(b,"tl_font"+e);g.value=f.annotateUI_textProperties.font;g=create_input_hidden(b, "tl_size"+e);g.value=f.annotateUI_textProperties.size;g=create_input_hidden(b,"tl_color"+e);g.value=f.annotateUI_textProperties.color;g=create_input_hidden(b,"tl_extra"+e);g.value=f.annotateUI_textProperties.extra;g=create_input_hidden(b,"tl_x"+e);g.value=parseInt(f.style.left);g=create_input_hidden(b,"tl_y"+e);g.value=parseInt(f.style.top);e++}d=d.nextSibling}if(e){create_input_hidden(b,"tl_count").value=e;create_input_hidden(b,"tl_width").value=c.offsetWidth;create_input_hidden(b,"tl_height").value= c.offsetHeight}},_handle_download:function(b){annotateUI.storeToForm("downloadform");var c=document.getElementById("downloadform");c.action=b.href;c.submit()},_update_state:function(){annotateUI._clear_state_timer();annotateUI._stateTimerId=window.setTimeout(delegate(annotateUI,"_update_state_do"),800)},_clear_state_timer:function(){if(annotateUI._stateTimerId){window.clearTimeout(annotateUI._stateTimerId);annotateUI._stateTimerId=0}},_update_state_do:function(){annotateUI._clear_state_timer();var b= document.getElementById("session-key");if(b&&b.value){var c=document.getElementById("sourceimage-cascade");if(c&&c.value){var d=document.getElementById("textlayer"),e=d.firstChild;b="sid="+encodeURIComponent(b.value);b+="&src="+encodeURIComponent(c.value);for(c=0;e;){var g=e.firstChild;if(g&&g.annotateUI_textProperties){b+="&tl_text"+c+"="+encodeURIComponent(g.annotateUI_textProperties.text);b+="&tl_font"+c+"="+encodeURIComponent(g.annotateUI_textProperties.font);b+="&tl_size"+c+"="+encodeURIComponent(g.annotateUI_textProperties.size); b+="&tl_color"+c+"="+encodeURIComponent(g.annotateUI_textProperties.color);b+="&tl_extra"+c+"="+encodeURIComponent(g.annotateUI_textProperties.extra);b+="&tl_x"+c+"="+encodeURIComponent(parseInt(g.style.left));b+="&tl_y"+c+"="+encodeURIComponent(parseInt(g.style.top));c++}e=e.nextSibling}if(c){b+="&tl_count="+encodeURIComponent(c);b+="&tl_width="+encodeURIComponent(d.offsetWidth);b+="&tl_height="+encodeURIComponent(d.offsetHeight);d=annotateUI._stateNotification;d.open("POST","/annotate/wst",true); d.setRequestHeader("Content-type","application/x-www-form-urlencoded");d.setRequestHeader("Content-length",b.length);d.setRequestHeader("Connection","close");d.send(b)}}}},init:function(){var b=annotateUI._stateFetcher,c=document.getElementById("session-key");if(c&&c.value){var d=document.getElementById("sourceimage-cascade");if(d&&d.value){c="sid="+encodeURIComponent(c.value);c+="&src="+encodeURIComponent(d.value);b.open("POST","/annotate/rst",true);b.onreadystatechange=delegate(annotateUI,"init_do", b);b.setRequestHeader("Content-type","application/x-www-form-urlencoded");b.setRequestHeader("Content-length",c.length);b.setRequestHeader("Connection","close");b.send(c)}}},init_do:function(b){if(!(!b||b.readyState!=4))if(b.status==200){var c=null;try{c=JSON.parse(b.responseText)}catch(d){return}for(b=0;b<c.length;b++)annotateUI.createTextElement(c[b],1)}},showTextlayer:function(b){document.getElementById("textlayer").style.display=b?"block":"none"},resizeTextLayer:function(){}}; function create_input_hidden(b,c){if(b.elements[c])return b.elements[c];var d=document.createElement("input");d.type="hidden";d.name=c;b.appendChild(d);return d}addEvent(window,"load",delegate(annotateUI,"init")); var ImageSelectBox={_idCounter:0,_registerClass:"imageselect",install:function(){for(var b=document.getElementsByTagName("select"),c=0;c<b.length;c++)if(b[c].className&&b[c].className==ImageSelectBox._registerClass)if(b[c].offsetWidth)if(!document.getElementById("ImageSelectBox-overlay-"+b[c].id)){var d=b[c].getElementsByTagName("option");if(d.length){var e=document.createElement("div");e.style.position="relative";e.style.clear="none";e.style.display="inline";b[c].parentNode.insertBefore(e,b[c]); e.appendChild(b[c]);e=document.createElement("div");e.setAttribute("id","ImageSelectBox-dropdown"+ImageSelectBox._idCounter);e.style.display="none";e.style.width=b[c].offsetWidth+"px";e.style.overflow="auto";e.style.height="300px";e.style.position="absolute";e.style.left=b[c].offsetLeft+"px";e.style.background="#fff";e.className="ImageSelectBox-dropdown";e.style.top=b[c].offsetTop-parseInt(e.style.height)+"px";for(var g="",f=0;f<d.length;f++){g+="<div>";g+="<a href=\"javascript:ImageSelectBox.setOption('"+ b[c].id+"', '"+d[f].value+"',"+ImageSelectBox._idCounter+')">';g+='<img src="/static/images/dropdowns/'+b[c].id+"/"+d[f].value+'.jpg" alt="'+d[f].text+'" title="'+d[f].text+'">';g+=d[f].text+"</a>";g+="</div>"}e.innerHTML=g;d=document.createElement("div");d.setAttribute("id","ImageSelectBox-overlay-"+b[c].id);d.style.position="absolute";d.style.width=b[c].offsetWidth+"px";d.style.height=(b[c].offsetHeight?b[c].offsetHeight:parseInt(b[c].style.height))+"px";d.style.left=b[c].offsetLeft+"px";d.style.top= b[c].offsetTop+"px";d.style.background="url('/static/images/transparent.gif')";d.foo=e.id;d.onclick=function(){this.blur();ImageSelectBox.toggleDropdown(this.foo)};b[c].parentNode.insertBefore(d,b[c]);b[c].parentNode.insertBefore(e,b[c]);ImageSelectBox._idCounter++}}},setOption:function(b,c,d){if(b=document.getElementById(b)){b.value=c;b.onchange&&b.onchange()}ImageSelectBox.showDropdown("ImageSelectBox-dropdown"+d,0)},showDropdown:function(b,c){if(b=document.getElementById(b))if(c){b.style.display= "block";bringElementToTop(b)}else b.style.display="none"},toggleDropdown:function(b){var c=document.getElementById(b);if(c)ImageSelectBox.showDropdown(b,c.style.display=="block"?0:1)},hideAllDropdowns:function(){for(var b=0;b<ImageSelectBox._idCounter;b++){var c=document.getElementById("ImageSelectBox-dropdown"+b);if(c)c.style.display="none"}}};addEvent(window,"load",ImageSelectBox.install);var xmlhttp_subfiltersettings=new_xmlhttp(); function updatebackgroundfiltercontrols(b){b=b.value;if(!b)return false;var c=document.getElementById("backgroundfilter-controls");if(c){c.style.display="none";c=xmlhttp_subfiltersettings;c.open("GET","/filter-controls/"+b,true);c.onreadystatechange=subfilterctrls_onreadystatechange;c.send(null)}} function subfilterctrls_onreadystatechange(){var b=xmlhttp_subfiltersettings;if(!(!b||b.readyState!=4||b.status!=200)){var c=document.getElementById("backgroundfilter-controls");if(c){c.innerHTML=b.responseText;c.style.display="block";jscolor&&jscolor.init()}}} var QRU={_img:null,_imgW:0,_imgH:0,_timerId:0,_timerTimeoutDefault:220,_timerTimeout:220,enqueue:function(){QRU._timerId&&window.clearTimeout(QRU._timerId);QRU._timerId=window.setTimeout(delegate(QRU,"send_request"),QRU._timerTimeout)},send_request:function(){QRU._timerId&&window.clearTimeout(QRU._timerId);QRU._timerTimeout*=2.5;var b=document.getElementById("filter-settings-form");if(b){var c=new_xmlhttp();if(c){b=urlencode_form(b);if(b.length){TPEditorUI.showLoadIndicator(true);c.open("POST","/qru/"+ wsEffect,true);c.onreadystatechange=delegate(QRU,"onreadystatechange",c);c.setRequestHeader("Content-type","application/x-www-form-urlencoded");c.setRequestHeader("Content-length",b.length);c.setRequestHeader("Connection","close");c.send(b)}}}},onreadystatechange:function(b){if(!(!b||b.readyState!=4||b.status!=200)){b=b.responseText.split(",");if(b.length==5){QRU._imgW=b[0];QRU._imgH=b[1];QRU._imgSK=b[2];QRU._imgFN=b[3];QRU._img=new Image;QRU._img.onload=delegate(QRU,"onload_render");QRU._img.src= "/image-sessions/"+b[2]+"/"+b[3]}}},onload_render:function(){var b=document.getElementById("rendered-image");document.getElementById("filter-settings-form");b.src=QRU._img.src;b.width=QRU._imgW;b.height=QRU._imgH;setStyle(b,"width:"+QRU._imgW+"px;height:"+QRU._imgH+"px");setStyle(document.getElementById("image-container"),"width:"+QRU._imgW+"px");setStyle(document.getElementById("image-container-wrapper"),"width:"+QRU._imgW+"px");setStyle(document.getElementById("textlayer"),"width:"+QRU._imgW+"px;height:"+ QRU._imgH+"px");b=1;for(var c=null;c=document.getElementById("download"+b);){c.href="/download/"+QRU._imgSK+"/"+QRU._imgFN;b++}for(b=1;c=document.getElementById("downloadhalf"+b);){c.href="/downloadhalf/"+QRU._imgSK+"/"+QRU._imgFN;b++}if(window.sendpic_clientInit){for(b=1;c=document.getElementById("img2mobile"+b);){c.rel="/mobile/"+QRU._imgSK+"/"+QRU._imgFN;b++}window.sendpic_clientInit()}document.getElementById("sourceimage-cascade").value=QRU._imgFN;TPEditorUI.showLoadIndicator(false);QRU._timerTimeout= QRU._timerTimeoutDefault}};function qru_do(){TPEditorUI.cancelUI();annotateUI.storeToForm("filter-settings-form");QRU&&QRU.enqueue()}TPEditorUI={showLoadIndicator:function(b){var c=document.getElementById("editorUI-loadindicator");if(c)c.style.display=b?"block":"none"},cancelUI:function(){resizeUI.cancelUI()},undofilter:function(){var b=document.getElementById("effect-cascade2");if(b){b.action="/photo-effects/editor";b.elements.src.value="";b.submit();return false}}}; function mfsf_onsubmit(){annotateUI.storeToForm("filter-settings-form");return true}if(!this.JSON)this.JSON={}; (function(){function b(j){return j<10?"0"+j:j}function c(j){g.lastIndex=0;return g.test(j)?'"'+j.replace(g,function(l){var n=i[l];return typeof n==="string"?n:"\\u"+("0000"+l.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+j+'"'}function d(j,l){var n,p,r=f,o,m=l[j];if(m&&typeof m==="object"&&typeof m.toJSON==="function")m=m.toJSON(j);if(typeof k==="function")m=k.call(l,j,m);switch(typeof m){case "string":return c(m);case "number":return isFinite(m)?String(m):"null";case "boolean":case "null":return String(m); case "object":if(!m)return"null";f+=h;o=[];if(Object.prototype.toString.apply(m)==="[object Array]"){p=m.length;for(j=0;j<p;j+=1)o[j]=d(j,m)||"null";l=o.length===0?"[]":f?"[\n"+f+o.join(",\n"+f)+"\n"+r+"]":"["+o.join(",")+"]";f=r;return l}if(k&&typeof k==="object"){p=k.length;for(j=0;j<p;j+=1){n=k[j];if(typeof n==="string")if(l=d(n,m))o.push(c(n)+(f?": ":":")+l)}}else for(n in m)if(Object.hasOwnProperty.call(m,n))if(l=d(n,m))o.push(c(n)+(f?": ":":")+l);l=o.length===0?"{}":f?"{\n"+f+o.join(",\n"+f)+ "\n"+r+"}":"{"+o.join(",")+"}";f=r;return l}}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+b(this.getUTCMonth()+1)+"-"+b(this.getUTCDate())+"T"+b(this.getUTCHours())+":"+b(this.getUTCMinutes())+":"+b(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var e=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, g=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,f,h,i={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},k;if(typeof JSON.stringify!=="function")JSON.stringify=function(j,l,n){var p;h=f="";if(typeof n==="number")for(p=0;p<n;p+=1)h+=" ";else if(typeof n==="string")h=n;if((k=l)&&typeof l!=="function"&&(typeof l!=="object"||typeof l.length!=="number"))throw new Error("JSON.stringify");return d("", {"":j})};if(typeof JSON.parse!=="function")JSON.parse=function(j,l){function n(p,r){var o,m,q=p[r];if(q&&typeof q==="object")for(o in q)if(Object.hasOwnProperty.call(q,o)){m=n(q,o);if(m!==undefined)q[o]=m;else delete q[o]}return l.call(p,r,q)}e.lastIndex=0;if(e.test(j))j=j.replace(e,function(p){return"\\u"+("0000"+p.charCodeAt(0).toString(16)).slice(-4)});if(/^[\],:{}\s]*$/.test(j.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+j+")");return typeof l==="function"?n({"":j},""):j}throw new SyntaxError("JSON.parse");}})();
