SocialEngineAPI.Tags=new Class({Implements:[Options],Base:{},isTagging:false,newtag:false,tags:[],options:{ajaxURL:"misc_js.php",ajaxMethod:"post",ajaxSecure:false,canTag:false,type:false,media_id:false,media_dir:false,object_owner:false,object_owner_id:false},initialize:function(a){this.setOptions(a);if(this.options.initialTotal){this.total=this.options.initialTotal}var b=this;window.addEvent("domready",function(){b.showTagForm()})},showTagForm:function(){var e="";var d=this;if(this.options.canTag){e+="<div class='media_photo_tagform_titlebar'><img src='images/icons/photos16.gif' class='icon' />"+this.Base.Language.Translate(1212)+"</div><div style='padding: 7px;'><div style='text-align: left;'><div style='font-size: 7pt; margin-bottom: 5px;'>"+this.Base.Language.Translate(1213)+"</div><div style='text-align: center;'><input type='text' style='width: 130px; padding-left: 4px; font-size: 8pt;' name='media_photo_tag' id='media_photo_tag' class='text' maxlength='40'/></div></div><div id='media_photo_friendlist' class='media_photo_friendlist'>";if(d.Base.Viewer.user_exists){e+="<div><a href='javascript:void(0)' id='tag_me'>"+d.Base.Viewer.user_displayname+d.Base.Language.Translate(1214)+"</a></div>"}e+="</div><div><input type='button' class='button' name='save' id='tag_save' value='"+d.Base.Language.Translate(1215)+"' />&nbsp;&nbsp;<input type='button' class='button' id='tag_cancel' name='cancel' value='"+d.Base.Language.Translate(39)+"' /></div></div>";var a=new Element("div",{id:"media_photo_tagform","class":"media_photo_tagform",html:e});var c=$("media_photo_div");a.inject(c);if(a.getElement("input[id=tag_cancel]")){a.getElement("input[id=tag_cancel]").addEvent("click",function(){d.cancelTag()})}if(a.getElement("input[id=tag_save]")){a.getElement("input[id=tag_save]").addEvent("click",function(){d.saveTag(0)})}if(a.getElement("a[id=tag_me]")){a.getElement("a[id=tag_me]").addEvent("click",function(){d.saveTag(d.Base.Viewer.user_info.user_id)})}var b=new Request.JSON({secure:false,url:"misc_js.php?task=friends_all",onComplete:function(f){d.addFriendToList(f.friends)}}).send()}},addFriendToList:function(a){var b=this;a.each(function(f){for(var c in f){var e=new Element("div",{id:"friend_div_"+c});var d=new Element("a",{href:"javascript:void(0)",id:"friend_link_"+c,html:f[c]}).inject(e);e.inject($("media_photo_friendlist"));$("friend_link_"+c).addEvent("click",function(){b.saveTag(c)})}})},insertTag:function(a,l,m,j,h,k,i,c){var f="";var g=this;if($("media_tags").style.display=="none"){$("media_tags").style.display="block"}else{if(g.tags.length!=0){f='<span id="tag_comma_'+a+'">, </span>'}}var d=new Element("span",{id:"full_tag_"+a,html:f});if(l!=""){var e=new Element("a",{href:l,id:"tag_link_"+a,html:m}).inject(d)}else{var e=new Element("span",{id:"tag_link_"+a,html:m,styles:{cursor:"pointer"}}).inject(d)}if(g.Base.Viewer.user_exists&&(g.Base.Viewer.user_info.user_username==c||g.Base.Viewer.user_info.user_username==g.Base.Owner.user_info.user_username)){var b=$(d).get("html");$(d).set("html",b," (<a href='javascript:void(0);' id='new_removetag_link'>"+g.Base.Language.Translate(1228)+"</a>)")}d.inject($("media_tags"));g.createTag(a,m,j,h,k,i);$("tag_link_"+a).addEvent("mouseover",function(){g.showTag(a)});$("tag_link_"+a).addEvent("mouseout",function(){g.hideTag(a)});if($("new_removetag_link")){$("new_removetag_link").addEvent("click",function(){g.removeTag(a)});$("new_removetag_link").set("id","removetag_link_"+a)}g.tags.push(a)},createTag:function(f,d,c,b,e,a){var g=this;new Element("div",{id:"tag_"+f,html:'<img src="./images/trans.gif" width="100%" height="100%" />',"class":"tag_div_hidden",styles:{width:(parseInt(e)-4)+"px",height:(parseInt(a)-4)+"px",top:c+"px",left:b+"px"}}).inject($("media_photo_div"));new Element("div",{id:"tag_label_"+f,html:d,"class":"tag_label",styles:{display:"none",top:(parseInt(c)+parseInt(a)+10)+"px",left:b+"px"}}).inject($("media_photo_div"));$("tag_"+f).addEvent("mouseover",function(){g.showTag(f)});$("tag_"+f).addEvent("mouseout",function(){g.hideTag(f)})},showTag:function(a){$("tag_"+a).className="tag_div";$("tag_label_"+a).style.display="block"},hideTag:function(a){$("tag_"+a).className="tag_div_hidden";$("tag_label_"+a).style.display="none"},addTag:function(){if(!this.isTagging){this.isTagging=true;this.newtag=new MooCrop("media_photo");var b=this;var a=$("media_photo_tagform").inject(b.newtag.wrapper);a.setStyles({top:this.newtag.crop.bottom+10,left:this.newtag.crop.right+10,display:"block"});this.newtag.addEvent("onBegin",function(f,e,d,c){a.setStyle("display","none")});this.newtag.addEvent("onCrop",function(f,e,d,c){a.setStyles({top:e.bottom+10,left:e.right+10,display:"none"})});this.newtag.addEvent("onComplete",function(f,e,d,c){a.setStyle("display","block")})}},cancelTag:function(){if(this.isTagging){$("media_photo_tag").value="";$("media_photo_tagform").inject("media_photo_div").setStyle("display","none");var a=this.newtag.removeOverlay.bind(this.newtag);a();this.isTagging=false}},saveTag:function(e){if(this.isTagging){if(this.options.object_owner&&this.options.object_owner_id){var f=this.options.object_owner;var b=this.options.object_owner_id;var c=""}else{var f="";var b="";var c=this.Base.Owner.user_info.user_username}var d="misc_js.php?task=tag_do&mediatag_user_id="+e+"&mediatag_text="+encodeURIComponent($("media_photo_tag").value)+"&mediatag_x="+this.newtag.crop.top+"&mediatag_y="+this.newtag.crop.left+"&mediatag_height="+this.newtag.crop.height+"&mediatag_width="+this.newtag.crop.width+"&user="+c+"&object_owner="+f+"&object_owner_id="+b+"&type="+this.options.type+"&media_id="+this.options.media_id+"&media_dir="+this.options.media_dir;$("ajaxframe").src=d;$("media_photo_tag").value="";$("media_photo_tagform").inject("media_photo_div").setStyle("display","none");var a=this.newtag.removeOverlay.bind(this.newtag);a();this.isTagging=false}},removeTag:function(e){if(this.options.object_owner&&this.options.object_owner_id){var d=this.options.object_owner;var a=this.options.object_owner_id;var b=""}else{var d="";var a="";var b=this.Base.Owner.user_info.user_username}var c="misc_js.php?task=tag_remove&mediatag_id="+e+"&user="+b+"&object_owner="+d+"&object_owner_id="+a+"&type="+this.options.type+"&media_id="+this.options.media_id;$("ajaxframe").src=c;$("tag_"+e).destroy();$("tag_label_"+e).destroy();$("full_tag_"+e).destroy();if(this.tags.indexOf(e)==0&&$("tag_comma_"+this.tags[1])){$("tag_comma_"+this.tags[1]).destroy()}this.tags.splice(this.tags.indexOf(e),1);if(this.tags.length==0){$("media_tags").style.display="none"}}});var MooCrop=new Class({calculateHandles:true,current:{},options:{maskColor:"black",maskOpacity:".3",handleColor:"#FFFFFF",handleWidth:"5px",handleHeight:"5px",cropBorder:"1px dashed #FFFFFF",min:{width:50,height:50},showMask:true,showHandles:false},initialize:function(b,a){this.setOptions(a);this.img=$(b);if(this.img.get("tag")!="img"){return false}this.resizeFunc=this.refresh.bindWithEvent(this);this.removeFunc=this.removeListener.bind(this);this.buildOverlay();this.setup()},setup:function(){$(this.cropArea).setStyles({width:this.options.min.width,height:this.options.min.height,top:(this.img.height-this.options.min.height)/2,left:(this.img.width-this.options.min.width)/2});this.current.crop=this.crop=this.getCropArea();this.handleWidthOffset=this.options.handleWidth.toInt()/2;this.handleHeightOffset=this.options.handleHeight.toInt()/2;this.fixBoxModel();this.drawMasks();this.positionHandles()},getCropArea:function(){var a=this.cropArea.getCoordinates();a.left-=this.offsets.x;a.right-=this.offsets.x;a.top-=this.offsets.y;a.bottom-=this.offsets.y;return a},fixBoxModel:function(){var c=this.boxDiff=(this.crop.width-this.options.min.width)/2;var a=this.bounds={top:c,left:c,right:this.img.width+(c*2),bottom:this.img.height+(c*2),width:this.options.min.width+(c*2),height:this.options.min.height+(c*2)};this.wrapper.setStyles({width:a.right,height:a.bottom,background:"url("+this.img.src+") no-repeat "+c+"px "+c+"px"});this.north.setStyle("width",a.right);this.south.setStyle("width",a.right)},activate:function(a,b){a.stop();this.current={x:a.page.x,y:a.page.y,handle:b,crop:this.current.crop};if(this.current.handle=="NESW"&&!this.options.showHandles){this.hideHandles()}this.fireEvent("onBegin",[this.img.src,this.getCropInfo(),this.bounds,b]);document.addEvent("mousemove",this.resizeFunc);document.addEvent("mouseup",this.removeFunc)},removeListener:function(){if(this.current.handle=="NESW"&&!this.options.showHandles){this.showHandles()}document.removeEvent("mousemove",this.resizeFunc);document.removeEvent("mouseup",this.removeFunc);this.crop=this.current.crop;this.fireEvent("onComplete",[this.img.src,this.getCropInfo(),this.bounds,this.current.handle])},refresh:function(a){var e=this.current.x-a.page.x;var d=this.current.y-a.page.y;var i=this.bounds;var h=this.crop;var f=this.current.handle;var k={};var j=(f.length>2)?true:false;if(f.contains("S")){if(h.bottom-d>i.bottom){d=h.bottom-i.bottom}if(!j){if((h.height-d)<i.height){d=h.height-i.height}k.height=h.height-d}}if(f.contains("N")){if(h.top-d<i.top){d=h.top}if(!j){if((h.height+d)<i.height){d=i.height-h.height}k.height=h.height+d}k.top=h.top-d}if(f.contains("E")){if(h.right-e>i.right){e=h.right-i.right}if(!j){if((h.width-e)<i.width){e=h.width-i.width}k.width=h.width-e}}if(f.contains("W")){if(h.left-e<i.left){e=h.left}if(!j){if((h.width+e)<i.width){e=i.width-h.width}k.width=h.width+e}k.left=h.left-e}var g=$merge(k);if($defined(k.width)){k.width-=this.boxDiff*2}if($defined(k.height)){k.height-=this.boxDiff*2}this.cropArea.setStyles(k);this.getCurrentCoords(g);this.drawMasks();this.positionHandles();this.fireEvent("onCrop",[this.img.src,this.getCropInfo(),i,f])},getCurrentCoords:function(b){var a=$merge(this.crop);if($defined(b.left)){a.left=b.left;if($defined(b.width)){a.width=b.width}else{a.right=a.left+a.width}}if($defined(b.top)){a.top=b.top;if($defined(b.height)){a.height=b.height}else{a.bottom=a.top+a.height}}if($defined(b.width)&&!$defined(b.left)){a.width=b.width;a.right=a.left+a.width}if($defined(b.height)&&!$defined(b.top)){a.height=b.height;a.bottom=a.top+a.height}this.current.crop=a},drawMasks:function(){if(!this.options.showMask){return}var a=this.bounds;var e=this.current.crop;var d=this.current.handle;this.north.setStyle("height",e.top+"px");this.south.setStyle("height",a.bottom-e.bottom+"px");this.east.setStyles({height:e.height+"px",width:a.right-e.right+"px",top:e.top+"px",left:e.right+"px"});this.west.setStyles({height:e.height+"px",width:e.left+"px",top:e.top+"px"})},positionHandles:function(){if(!this.calculateHandles){return}var d=this.current.crop;var a=this.handleWidthOffset;var b=this.handleHeightOffset;this.handles.get("N").setStyles({left:d.width/2-a+"px",top:-b+"px"});this.handles.get("NE").setStyles({left:d.width-a+"px",top:-b+"px"});this.handles.get("E").setStyles({left:d.width-a+"px",top:d.height/2-b+"px"});this.handles.get("SE").setStyles({left:d.width-a+"px",top:d.height-b+"px"});this.handles.get("S").setStyles({left:d.width/2-a+"px",top:d.height-b+"px"});this.handles.get("SW").setStyles({left:-a+"px",top:d.height-b+"px"});this.handles.get("W").setStyles({left:-a+"px",top:d.height/2-b+"px"});this.handles.get("NW").setStyles({left:-a+"px",top:-b+"px"})},hideHandles:function(){this.calculateHandles=false;this.handles.each(function(a){a.setStyle("display","none")})},showHandles:function(){this.calculateHandles=true;this.positionHandles();this.handles.each(function(a){a.setStyle("display","block")})},buildOverlay:function(){var b=this.options;this.wrapper=new Element("div",{styles:{"z-index":100,position:"relative",width:this.img.width,height:this.img.height,background:"url("+this.img.src+") no-repeat","float":this.img.getStyle("float"),"margin-left":"auto","margin-right":"auto"}}).injectBefore(this.img);this.img.setStyle("display","none");this.offsets={x:this.wrapper.getLeft(),y:this.wrapper.getTop()};this.wrapper.addEvent("mouseover",function(c){return false});if(this.options.showMask){var a={position:"absolute",overflow:"hidden","background-color":b.maskColor,opacity:b.maskOpacity};this.north=new Element("div",{styles:$merge(a,{left:"0px"})}).injectInside(this.wrapper);this.south=new Element("div",{styles:$merge(a,{bottom:"0px",left:"0px"})}).injectInside(this.wrapper);this.east=new Element("div",{styles:a}).injectInside(this.wrapper);this.west=new Element("div",{styles:$merge(a,{left:"0px"})}).injectInside(this.wrapper)}this.cropArea=new Element("div",{styles:{position:"absolute",top:"0px",left:"0px",border:b.cropBorder,cursor:"move"},events:{dblclick:function(){this.fireEvent("onDblClk",[this.img.src,this.getCropInfo(),this.bounds])}.bind(this),mousedown:this.activate.bindWithEvent(this,"NESW")}}).injectInside(this.wrapper);this.handles=new Hash();["N","NE","E","SE","S","SW","W","NW"].each(function(c){this.handles.set(c,new Element("div",{styles:{position:"absolute","background-color":b.handleColor,width:b.handleWidth,height:b.handleHeight,overflow:"hidden",cursor:(c.toLowerCase()+"-resize")},events:{mousedown:this.activate.bindWithEvent(this,c)}}).injectInside(this.cropArea))},this)},getCropInfo:function(){var a=$merge(this.current.crop);a.width-=this.boxDiff*2;a.height-=this.boxDiff*2;return a},removeOverlay:function(){this.wrapper.destroy();this.img.setStyle("display","")}});MooCrop.implement(new Events,new Options);