function photonote_container(a,b){this.element=a;this.notes=new Array();this.enabled=true;this.is_editing=false;this.is_showing=false;this.note_shown=false;this.user_id=glob_user_id;this.doc_id=b;Event.observe(this.element,"mouseover",this.on_mouseover.bind(this));Event.observe(this.element,"mouseout",this.on_mouseout.bind(this))}photonote_container.prototype.on_mouseover=function(){clearTimeout(this.timer);if(!this.is_editing&&!this.is_showing){this.show_all_notes()}};photonote_container.prototype.on_mouseout=function(a){clearTimeout(this.timer);if(!this.is_editing){this.timer=setTimeout(function(){this.hide_all_notes();this.is_showing=false;this.note_shown=false}.bind(this),200)}};photonote_container.prototype.on_click=function(f){return;if(this.is_editing){var a=f.clientX-this.element.offsetLeft,g=f.clientY-this.element.offsetTop;var d=this.note_shown;var b=_pi(d.rect.width);var c=_pi(d.rect.height);d.rect.left=_pi(a-b/2);d.rect.top=_pi(g-c/2);d.place_note();d.highlight_textarea()}};
photonote_container.prototype.add_note=function(b){if(this.is_editing){return}var a=new photonote(b);if(a.id){a.hide_note()}this.notes[this.notes.length]=a;a.container=this;this.element.appendChild(a.gui.element_rect);this.element.appendChild(a.gui.element_note);if(!a.id){a.select()}clearTimeout(this.timer);IOL.debug("new note "+b.comment_id)};photonote_container.prototype.delete_note=function(a){try{a.unselect()}catch(b){}this.element.removeChild(a.gui.element_rect);this.element.removeChild(a.gui.element_note);this.notes.splice(this.notes.indexOf(a),1)};photonote_container.prototype.show_all_notes=function(){this.enabled=true;for(var a=0;a<this.notes.length;a++){this.notes[a].show_note()}};photonote_container.prototype.hide_all_notes=function(){this.enabled=false;for(var a=0;a<this.notes.length;a++){this.notes[a].hide_note()}};photonote_container.prototype.hide_all_notes_text=function(){for(var a=0;a<this.notes.length;a++){this.notes[a].hide_note_text()}};photonote_container.prototype.disable_all_notes=function(){for(var a=0;
a<this.notes.length;a++){this.notes[a].disable_note()}};function photonote(c){this.id=c.note_id;this.html=c.content;this.text=c.content;this.coords=c.coords;this.type=c.type;this.status=1;this.user_id=c.user_id;this.user_title=Data.user[c.user_id].title;this.is_yours=(this.user_id==glob_user_id)?true:false;this.profile_id=c.profile_id;this.profile_title=c.profile_title;this.profile_doc_url=c.profile_doc_url;if(this.coords){this.rect=new photonote_rect(this.coords[0],this.coords[1],this.coords[2],this.coords[3])}else{if(c.x1){this.rect=new photonote_rect(c.x1,c.y1,(c.x2-c.x1),(c.y2-c.y1))}else{this.rect=new photonote_rect(10,10,50,50)}}var b={selected:false,container:null,dragresize:null,rect_old:null,offset_x:-5,offset_y:1,gui:null,timer:null};for(var d in b){this[d]=b[d]}if(this.type==1){if(!Data.user[this.profile_id]){var a=IOL.Data.load("user",this.profile_id);if(a.success){IOL.debug("had to load user "+this.profile_id,"warn")}else{IOL.debug("failed to load user "+this.profile_id,"err");
this.status=0}}}this.create_note()}photonote.prototype.create_note=function(){if(!this.status){return}this.gui=new photonote_gui();var q=this;var c=document.createElement("div");c.className="pn-rect";if(this.is_yours){Event.observe(c,"click",function(A){q.select();Event.stop(A)})}var v=document.createElement("div");v.className="pn-rect-border1";var u=document.createElement("div");u.className="pn-rect-border2";var d=document.createElement("div");d.className="pn-rect-inn";Event.observe(d,"mouseover",function(){clearTimeout(q.timer);q.timer=0;q.show_note_text()});Event.observe(d,"mouseout",function(){if(!q.selected&&!q.timer){q.timer=setTimeout(function(){q.hide_note_text();clearTimeout(q.timer);q.timer=0},500)}});c.appendChild(v).appendChild(u).appendChild(d);var e=document.createElement("div");e.className="pn-note";var t=document.createElement("table");var a=document.createElement("tbody");var b=document.createElement("tr");var i=document.createElement("td");e.appendChild(t);t.appendChild(a);
a.appendChild(b);b.appendChild(i);var z=document.createElement("div");if(this.is_yours){Event.observe(z,"click",function(){q.select()})}if(this.type==0){var k=document.createElement("div");k.innerHTML=this.html.nl2br()}else{if(this.type==1){var k=document.createElement("div");var h=document.createElement("img");h.src=Data.user[this.profile_id].doc_url;h.style.width="17px";h.style.height="17px";h.style.marginRight="5px";h.className="absmiddle";h.style.cursor="pointer";h.folder=Data.user[this.profile_id].folder;h.onclick=function(){document.location="/home/"+this.folder};if(this.is_yours){var o=document.createTextNode(Data.user[this.profile_id].title)}else{var o=document.createElement("a");o.href="/tag/"+glob_user.folder+"/profile/"+this.profile_id;o.innerHTML=Data.user[this.profile_id].title}k.appendChild(h);k.appendChild(o)}}z.appendChild(k);if(this.user_id!=glob_user_id){var j=document.createElement("div");j.style.marginTop="3px";var f=document.createElement("small");var n=document.createTextNode(_MSG.by+" ");
var r=document.createElement("a");r.href="/home/"+this.user_id;r.innerHTML=this.user_title;f.appendChild(n);f.appendChild(r);if(isyou){f.appendChild(document.createTextNode(" | "));var p=document.createElement("a");p.href="#";p.innerHTML=_MSG.suppress+"?";Event.observe(p,"click",function(A){Event.stop(A);if(confirm(_MSG.confirm_delete)){q.delete_note(q)}});f.appendChild(p)}j.appendChild(f);z.appendChild(j)}Event.observe(z,"mouseover",function(){clearTimeout(q.timer);q.timer=0;q.show_note_text()});Event.observe(z,"mouseout",function(){if(!q.selected&&!q.timer){q.timer=setTimeout(function(){q.hide_note_text();clearTimeout(q.timer);q.timer=0},30)}});if(this.is_yours){z.className="pn-note-text-you"}else{z.className="pn-note-text-other"}i.appendChild(z);var m=document.createElement("div");m.className="pn-note-edit";if(this.type==0){var w=document.createElement("div");w.className="pn-note-edit-text";var y=document.createElement("textarea");y.value=this.text;if(!this.id){y.setAttribute("default",this.text)
}w.appendChild(y);m.appendChild(w)}else{if(this.type==1){var w=document.createElement("div");w.className="pn-note-edit-text";var h=document.createElement("img");h.src=Data.user[this.profile_id].doc_url;h.style.width="17px";h.style.height="17px";h.style.marginRight="5px";h.className="absmiddle";var o=document.createTextNode(Data.user[this.profile_id].title);w.appendChild(h);w.appendChild(o);var y=document.createElement("input");y.setAttribute("type","hidden");y.value=w.innerHTML;w.appendChild(y);m.appendChild(w);m.appendChild(w)}}var s=document.createElement("div");s.style.marginTop="3px";var g=document.createElement("input");g.type="button";g.style.marginRight="5px";g.className="submit";g.value=_MSG.save;Event.observe(g,"click",function(){if(!q.id){var A=q.gui.textarea;if(A.value==A.getAttribute("default")){A.focus();A.select();return}}q.save(q);q.save_note(q)});s.appendChild(g);var x=document.createElement("input");x.type="button";x.style.marginRight="5px";x.className="reset";x.value=_MSG.cancel;
Event.observe(x,"click",function(){q.cancel()});s.appendChild(x);var l=document.createElement("input");l.type="button";l.style.marginRight="5px";l.className="reset";l.value=_MSG.suppress;Event.observe(l,"click",function(){if(confirm(_MSG.confirm_delete)){q.delete_note(q)}});s.appendChild(l);m.appendChild(s);i.appendChild(m);this.dragresize=new DragResize("pn-dragresize",{minWidth:10,minHeight:10,allowBlur:false});this.dragresize.isElement=function(B){if(B.className=="pn-rect"){try{this.minLeft=0;this.maxLeft=q.container.element.offsetWidth;this.minTop=0;this.maxTop=q.container.element.offsetHeight}catch(A){}return true}};this.dragresize.isInside=function(A,C){if(!q.container){return}var B=(A>q.container.element.offsetLeft&&A<(q.container.element.offsetLeft+q.container.element.offsetWidth)&&C>q.container.element.offsetTop&&C<(q.container.element.offsetTop+q.container.element.offsetHeight))?true:false;if(B&&!q.container.enabled&&!q.container.is_editing){q.container.show_all_notes()}else{if(!B&&q.container.enabled&&!q.container.is_editing&&(q.timer||!q.container.is_showing)){q.container.hide_all_notes()
}}};this.dragresize.isHandle=function(A){if(A.className=="pn-rect"){return true}};this.dragresize.ondragfocus=function(){q.gui.element_rect.style.cursor="move"};this.dragresize.ondragblur=function(){q.gui.element_rect.style.cursor="pointer"};this.dragresize.ondragstart=function(){q.highlight_textarea();q.place_note();if(q.rect_old==null){var A=q.rect;q.rect_old=new photonote_rect(A.left,A.top,A.width,A.height)}};this.dragresize.ondragmove=function(){var A=_pi(this.element.style.left);var D=_pi(this.element.style.top);var B=_pi(this.element.style.width);var C=_pi(this.element.style.height);q.rect.left=A;q.rect.top=D;q.rect.width=B;q.rect.height=C;q.place_note()};this.dragresize.onmouseover=function(){q.show_all_notes()};this.dragresize.onmouseout=function(){q.show_all_notes()};this.dragresize.apply(document);this.gui.element_rect=c;this.gui.element_note=e;this.gui.title=z;this.gui.edit=m;this.gui.textarea=y;this.gui.title=z;this.gui.butt_save=g;this.gui.butt_delete=l;this.place_note()};photonote.prototype.show_note_text=function(){if(this.container&&!this.container.is_editing&&this.gui.element_note.style.display!="block"){this.container.hide_all_notes_text();
this.container.disable_all_notes();this.enable_note();this.gui.element_rect.style.border="1px solid #D4D82D";this.gui.element_rect.style.margin="0";this.gui.element_note.style.display="block";this.container.is_showing=this.id;this.container.note_shown=this}};photonote.prototype.hide_note_text=function(){if(this.container.is_showing==this.id){this.container.is_showing=false;this.container.note_shown=false}this.gui.element_rect.style.border="0px solid #fbffcc";this.gui.element_rect.style.margin="1px";this.gui.element_note.style.display="none"};photonote.prototype.show_note=function(){this.gui.element_rect.style.display="block";this.gui.element_note.style.display="none"};photonote.prototype.hide_note=function(){this.gui.element_rect.style.display="none";this.gui.element_note.style.display="none"};photonote.prototype.disable_note=function(){this.dragresize.enabled=false};photonote.prototype.enable_note=function(){if(this.user_id==glob_user_id){this.dragresize.enabled=true}};photonote.prototype.place_note=function(){this.gui.element_rect.style.left=this.rect.left+"px";
this.gui.element_rect.style.top=this.rect.top+"px";this.gui.element_rect.style.width=this.rect.width+"px";this.gui.element_rect.style.height=this.rect.height+"px";this.gui.element_rect.firstChild.style.width=_pi(this.gui.element_rect.style.width)-2+"px";this.gui.element_rect.firstChild.style.height=_pi(this.gui.element_rect.style.height)-2+"px";this.gui.element_rect.firstChild.firstChild.style.width=_pi(this.gui.element_rect.style.width)-4+"px";this.gui.element_rect.firstChild.firstChild.style.height=_pi(this.gui.element_rect.style.height)-4+"px";this.gui.element_rect.firstChild.firstChild.firstChild.style.width=_pi(this.gui.element_rect.style.width)-4+"px";this.gui.element_rect.firstChild.firstChild.firstChild.style.height=_pi(this.gui.element_rect.style.height)-4+"px";if(this.container&&this.container.is_editing&&this.gui.element_note.offsetHeight>(this.container.element.offsetHeight-(this.rect.top+this.offset_y+this.rect.height))){this.gui.element_note.style.left=this.rect.left+this.offset_x+"px";
this.gui.element_note.style.top=this.rect.top-this.offset_y-this.gui.element_note.offsetHeight+"px"}else{this.gui.element_note.style.left=this.rect.left+this.offset_x+"px";this.gui.element_note.style.top=this.rect.top+this.offset_y+this.rect.height+"px"}};photonote.prototype.select=function(){if(this.container&&!this.container.is_editing){this.show_note_text();this.dragresize.select(this.gui.element_rect);this.selected=true;this.make_editable(true)}};photonote.prototype.unselect=function(){this.dragresize.deselect(this.gui.element_rect);this.selected=false;this.make_editable(false);this.hide_note_text()};photonote.prototype.save_note=function(b){var c=this.container.doc_id;var a=this;modal.say(_MSG.saving,{icon:"wait",area:this.container.element});var d={doc_id:c,note_id:b.id,type:b.type,content:b.text,x1:b.rect.left,y1:b.rect.top,x2:b.rect.left+b.rect.width,y2:b.rect.top+b.rect.height,profile_id:b.profile_id};if(window.glob_group){d.group_id=glob_group.group_id}IOL.API.request("doc.add.note",d,a)
};photonote.prototype.doc_add_note_onApi=function(d,b,a,c){if(d&&b.note){modal.say(_MSG.saved,{icon:"ok",timeout:1000,area:this.container.element});this.id=b.note.note_id}else{modal.say(_MSG.failed,{icon:"nok",area:this.container.element},1);this.cancel()}};photonote.prototype.delete_note=function(b){var c=this.container.doc_id;var a=this;modal.say(_MSG.saving,{icon:"wait",area:this.container.element});var d={doc_id:c,note_id:b.id};if(window.glob_group){d.group_id=glob_group.group_id}console.log("deleting note...");console.log(d);IOL.API.request("doc.del.note",d,a)};photonote.prototype.doc_del_note_onApi=function(d,b,a,c){if(d){modal.say(_MSG.suppressed,{icon:"ok",timeout:1000,area:this.container.element});this.container.delete_note(this)}else{modal.say(_MSG.failed,{icon:"nok",area:this.container.element},1);this.cancel()}};photonote.prototype.save=function(a){this.rect_old=null;this.text=this.gui.textarea.value;this.html=this.text;this.gui.title.innerHTML=this.html.nl2br();this.unselect();
this.place_note()};photonote.prototype.cancel=function(){if(!this.id){this.container.delete_note(this)}else{if(this.rect_old!=null){this.rect=this.rect_old}this.rect_old=null;this.gui.textarea.value=this.text;this.unselect();this.place_note()}};photonote.prototype.make_editable=function(a){this.container.is_editing=a;if(a){this.gui.element_note.style.minWidth="200px";this.gui.title.style.display="none";this.gui.edit.style.display="block";if(this.is_yours){this.gui.butt_save.style.display="inline"}else{this.gui.butt_save.style.display="none"}if(!this.id){this.gui.butt_delete.style.display="none"}else{this.gui.butt_delete.style.display="inline"}this.highlight_textarea()}else{this.gui.element_note.style.minWidth="50px";this.gui.title.style.display="block";this.gui.edit.style.display="none"}};photonote.prototype.highlight_textarea=function(){if(this.gui.edit.style.display=="block"){var a=this.gui.textarea;setTimeout(function(){try{a.focus();a.select()}catch(b){}},200)}};function photonote_gui(){this.element_rect=null;
this.element_note=null;this.title=null;this.edit=null;this.textarea=null;this.butt_save=null;this.butt_delete=null}function photonote_rect(d,c,a,b){this.left=_pi(d);this.top=_pi(c);this.width=_pi(a);this.height=_pi(b)}photonote_rect.prototype.toString=function(){return"left: "+this.left+", top: "+this.top+", width: "+this.width+", height: "+this.height};