/*    HTTP Host:  b.static.ak.fbcdn.net                                        */
/*    Generated:  December 11th 2009 1:21:34 AM PST                            */
/*      Machine:  10.16.139.110                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/5axkticoym0w0oss.pkg.js h:alyas2rz                        */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/5axkticoym0w0oss.pkg.js                                   */

if (window.CavalryLogger) { CavalryLogger.start_js(["js\/5axkticoym0w0oss.pkg.js"]); }

function PhotoTag(_L0,_L1,_L2,_L3){copy_properties(this,{centerPoint:new Vector2(_L0/100,_L1/100),photoOwnerId:_L2,photoId:_L3});copy_properties(this,{taggeeName:'',taggeeId:null,taggeeEmail:'',_saved:false,_pendingAsync:false});}copy_properties(PhotoTag,{SYNCING_ENDPOINT:'/ajax/photo_tagging_ajax.php',MAX_TAGS_PER_PHOTO:50,_tagList:{},_photoKey:function(_L0,_L1){return _L0+':'+_L1;},tagsForPhoto:function(_L0,_L1){var _L2=PhotoTag._photoKey(_L0,_L1);return PhotoTag._tagList[_L2]||[];},clearTagsForPhoto:function(_L0,_L1){var _L2=PhotoTag._photoKey(_L0,_L1);PhotoTag._tagList[_L2]=[];}});copy_properties(PhotoTag.prototype,{setTaggeeEmail:function(_L0){if(this.saved){Util.log('You cannot edit the email of a saved tag');return this;}else this.taggeeEmail=_L0;return this;},setTaggeeName:function(_L0){if(this.saved){Util.log('You cannot edit the name of a saved tag');return this;}else this.taggeeName=_L0;return this;},setTaggeeId:function(_L0){if(this.saved){Util.log('You cannot edit the id of a saved tag');}else this.taggeeId=_L0;return this;},absoluteCenter:function(_L0,_L1){return this.centerPoint.mul(_L0,_L1);},submit:function(_L0){if(!this.taggeeName&&!this.taggeeId){Util.log('No user, email, or string has been tagged yet');return;}else if(this._saved){Util.log('This tag has already been saved to the server.  You cannot '+'save it again');return;}else if(this._pendingAsync){return;}else if(PhotoTag.MAX_TAGS_PER_PHOTO<=PhotoTag.tagsForPhoto(this.photoId,this.photoOwnerId).length){Util.log('Cannot add more than %d tags to any given photo.  (pid: %d, '+'id: %d) is already at the limit.',PhotoTag.MAX_TAGS_PER_PHOTO,this.photoId,this.photoOwnerId);return;}_L0=_L0||bagofholding;var _L1={pid:this.photoId,id:this.photoOwnerId,subject:this.taggeeId,name:this.taggeeName,email:this.taggeeEmail,action:'add',x:this.centerPoint.x*100,y:this.centerPoint.y*100};this._pendingAsync=true;new AsyncRequest().setURI(PhotoTag.SYNCING_ENDPOINT).setData(_L1).setHandler(bind(this,this._submitHandler,_L0)).setErrorHandler(bind(this,this._submitHandler,_L0)).setFinallyHandler(bind(this,function(){this._pendingAsync=false;})).send();},remove:function(_L0,_L1){if(!this.taggeeName&&!this.taggeeId){Util.log('No user or name has been tagged yet');return;}else if(this._pendingAsync){return;}else if(!this._saved){this._removeLocal();return _L0(this,{});}_L0=_L0||bagofholding;var _L2={pid:this.photoId,id:this.photoOwnerId,subject:this.taggeeId,name:this.taggeeName,action:_L1||'remove'};this._pendingAsync=true;new AsyncRequest().setURI(PhotoTag.SYNCING_ENDPOINT).setData(_L2).setHandler(bind(this,this._removeHandler,_L0)).setFinallyHandler(bind(this,function(){this._pendingAsync=false;})).send();return false;},invite:function(_L0){var _L1={pid:this.photoId,id:this.photoOwnerId,subject:this.taggeeId,name:this.taggeeName,email:this.taggeeEmail,x:this.centerPoint.x*100,y:this.centerPoint.y*100};_L0=_L0||bagofholding;var _L2=new AsyncRequest().setURI('/ajax/invite_photo_tag.php').setHandler(_L0).setData(_L1);var _L3=new Dialog().setAsync(_L2).show();return false;},_removeLocal:function(){var _L0=PhotoTag._photoKey(this.photoId,this.photoOwnerId);var _L1=PhotoTag._tagList[_L0]||[];for(var i=0,len=_L1.length;i<len;i++)if(_L1[i]==this){_L1.splice(i,1);break;}},setLocalSave:function(){var _L0=PhotoTag._photoKey(this.photoId,this.photoOwnerId);var _L1=PhotoTag._tagList[_L0]=PhotoTag._tagList[_L0]||[];PhotoTag._tagList[_L0][_L1.length]=this;return this;},setSaved:function(){this._saved=true;return this.setLocalSave();},getText:function(){return this.taggeeName||this.taggeeEmail;},getTaggeeId:function(){return this.taggeeId;},_submitHandler:function(_L0,_L1){var _L2=_L1.getError();var _L3=_L1.getPayload();if(_L2){ErrorDialog.showAsyncError(_L1);if(!_L3['tag_success'])return;}this.setSaved();this.taggeeName=_L3.taggeeName;this.taggeeId=_L3.taggeeId;_L0(this,_L3);},_removeHandler:function(_L0,_L1){this._removeLocal();(_L0||bagofholding)(this,_L1.getPayload());}});
function PhotoTagViewer(_L0){if(PhotoTagViewer._instances[_L0])return PhotoTagViewer._instances[_L0];copy_properties(this,{minTagDistance:83,photoElementId:_L0,photoOwnerId:null,photoId:null,photoObjectId:null,tagShowCallback:bagofholding,tagHideCallback:bagofholding,showingTag:null,tagFrame:null,nameFrame:null,_taggingEnabled:false});this._getPhotoElement=bind(null,ge,_L0);this._destruct=function(){_L2.remove();this.hideTag();this.tagHideCallback();delete PhotoTagViewer._instances[_L0];};this._wait_for_load=function(_L3){_L3.deferUntil(image_has_loaded.bind(this,this._getPhotoElement()),100);};if(!this._getPhotoElement())throw new Error('No images with the id `'+_L0+'\' '+'found on the page.  PhotoTagViewer Abort.');var _L1=bind(this,this._photoMouseMove);var _L2=Event.listen(document,'mousemove',_L1);onunloadRegister(bind(this,this._destruct));PhotoTagViewer._instances[_L0]=this;}copy_properties(PhotoTagViewer,{_instances:{},getInstance:function(_L0){return PhotoTagViewer._instances[_L0];}});copy_properties(PhotoTagViewer.prototype,{setPhotoData:function(_L0,_L1){this.photoOwnerId=_L0;this.photoId=_L1;this.hideTag();this.tagHideCallback();return this;},setPhotoObjectId:function(_L0){this.photoObjectId=_L0;return this;},setMinTagDistance:function(_L0){this.minTagDistance=_L0;return this;},registerTagHover:function(_L0,_L1){if(!_L0&&!_L1){this.tagShowCallback=bind(this,this.showTagText);this.tagHideCallback=bind(this,this.hideTagText);}else{this.tagShowCallback=_L0;this.tagHideCallback=_L1;}return this;},enableTagging:function(){this._taggingEnabled=true;},disableTagging:function(){this._taggingEnabled=false;},_photoClick:function(_L0){if(!this._getPhotoElement())return this._destruct();if(!this._taggingEnabled)return true;var _L1=PhotoTag.tagsForPhoto(this.photoId,this.photoOwnerId);if(PhotoTag.MAX_TAGS_PER_PHOTO<=_L1.length){new ErrorDialog().showError(_tx("Too Many Tags"),_tx("A photo may only have up to {limit} tags. To add a new tag, you must first remove one of the existing tags on the photo.",{limit:PhotoTag.MAX_TAGS_PER_PHOTO}));return $E(_L0).kill();}},showTag:function(tag){if(!this._getPhotoElement())return this._destruct();if(!tag)return;if(this._isPhotoCropOn())return;this._wait_for_load(this._showTag.bind(this,tag));},_showTag:function(tag){if(!this.tagFrame){var _L1=document.createElement('div');_L1.style.width=(2*this.minTagDistance)+'px';_L1.style.height=(2*this.minTagDistance)+'px';CSS.addClass(_L1,'photo_tag_frame_inside');this.tagFrame=$N('div',null,_L1);CSS.addClass(this.tagFrame,'photo_tag_frame');this.tagFrame.onclick=bind(this,this._photoClick);DOMScroll.getScrollRoot().appendChild(this.tagFrame);}var _L2=Vector2.getElementPosition(this._getPhotoElement());var _L3=Vector2.getElementDimensions(this._getPhotoElement());var _L4=tag.absoluteCenter(_L3.x,_L3.y);var _L5=this._calculateWithinBounds(_L4,2*this.minTagDistance,this._getPhotoElement());var _L6=new Vector2(_L5.size,_L5.size);var _L7=_L6.mul(.5,.5);_L6.setElementDimensions(DOM.find(this.tagFrame,'div.photo_tag_frame_inside'));new Vector2(-10000,-100000,'document').setElementPosition(this.tagFrame);show(this.tagFrame);var _L8=Vector2.getElementDimensions(this.tagFrame).sub(_L5.size,_L5.size).mul(.5,.5);_L2.add(_L5.tagPosition).sub(_L7).sub(_L8).setElementPosition(this.tagFrame);},hideTag:function(){hide(this.tagFrame);},showTagText:function(tag){if(!this._getPhotoElement())return this._destruct();if(!tag||this._taggingEnabled)return;this._wait_for_load(this._showTagText.bind(this,tag));},_showTagText:function(tag){if(this.nameFrame)this.hideTagText();if(this._isPhotoCropOn())return;this.nameFrame=$N('div',null,$N('span',null,tag.getText()));CSS.addClass(this.nameFrame,'photo_tag_name_frame');DOMScroll.getScrollRoot().appendChild(this.nameFrame);var _L1=Vector2.getElementPosition(this._getPhotoElement());var _L2=Vector2.getElementDimensions(this._getPhotoElement());var _L3=tag.absoluteCenter(_L2.x,_L2.y);var _L4=this._calculateWithinBounds(_L3,2*this.minTagDistance,this._getPhotoElement());var _L5=Vector2.getElementDimensions(this.nameFrame);var _L6=new Vector2(_L5.x/2,8+_L5.y-_L4.size/2);_L1.add(_L4.tagPosition).sub(_L6).setElementPosition(this.nameFrame);show(this.nameFrame);},hideTagText:function(){if(this.nameFrame)DOM.remove(this.nameFrame);this.nameFrame=null;},_forceWithinBounds:function(_L0,_L1,_L2){_L0=_L0.sub(0,0);if(_L0.x<_L1){_L0.x=Math.min(_L1,_L2.x);}else if(_L0.x>_L2.x-_L1)_L0.x=Math.max(0,_L2.x-_L1);if(_L0.y<_L1){_L0.y=Math.min(_L1,_L2.y);}else if(_L0.y>_L2.y-_L1)_L0.y=Math.max(0,_L2.y-_L1);return _L0;},_calculateWithinBounds:function(_L0,_L1,_L2){var _L3=Vector2.getElementPosition(_L2);var _L4=Vector2.getElementDimensions(_L2);var _L5=Math.max(_L0.x-_L1/2,0);var _L6=Math.min(_L0.x+_L1/2,_L4.x);var top=Math.max(_L0.y-_L1/2,0);var _L8=Math.min(_L0.y+_L1/2,_L4.y);var _L0=new Vector2((_L6+_L5)/2,(top+_L8)/2);var _L9=Math.min(_L6-_L5,_L8-top);return {tagPosition:_L0,size:_L9};},_photoMouseMove:function(_L0){if(!this._getPhotoElement())return this._destruct();if(this._taggingEnabled)return;if(!this.tagShowCallback&&!this.tagHideCallback)return;var _L1=PhotoTag.tagsForPhoto(this.photoId,this.photoOwnerId);if(!_L1)return;var _L2=Vector2.getEventPosition(_L0);var _L3=Vector2.getElementPosition(this._getPhotoElement());var _L4=Vector2.getElementDimensions(this._getPhotoElement());var _L5=_L2.sub(_L3);if(_L5.x>0&&_L5.x<_L4.x&&_L5.y>0&&_L5.y<_L4.y){var _L6=_L4.magnitude();var _L7=null;for(var i=0;i<_L1.length;i++){var _L9=_L1[i].absoluteCenter(_L4.x,_L4.y);var _La=_L9.sub(_L5);var _Lb=_La.magnitude();if(Math.abs(_La.x)<=this.minTagDistance&&Math.abs(_La.y)<=this.minTagDistance&&_Lb<=_L6){_L6=_Lb;_L7=_L1[i];if(0==_Lb)break;}}}if(!_L7&&this.showingTag&&this.tagHideCallback){this.showingTag=null;this.tagHideCallback(this.showingTag);}else if(_L7&&this.tagShowCallback&&_L7!=this.showingTag){this.showingTag=_L7;this.tagShowCallback(_L7);}},_isPhotoCropOn:function(){return window['photocrop']&&window['photocrop'].instance&&true;}});
PhotoTagSelector=function(){var _L0;var _L1;var _L2;var _L3=false;var _L4=null;var _L5=[];var _L6=[];var _L7=false;var _L8=null;var _L9=null;var _La=null;var _Lb=false;var _Lc=false;var _Ld=bagofholding;var _Le=bagofholding;var _Lf=[];var _L10=0;var _L11=function(){_L1.value='';_L2.value='';PhotoTagSelector.exitInviteMode();};var _L12=function(){if(!_L3)return;var _L1e=_L1.value.toLowerCase().trim();_L1e=typeahead_source.flatten_string(_L1e);var _L1f=[];var _L20=[];for(var i=0,len=_L5.length;i<len;i++){var _L23=_L5[i];if(!_L1e||-1!=_L23['flat_name'].indexOf(_L1e))(_L23['rel']?_L20:_L1f).push(_L23['fragment']);}_L10=_L1f.length+_L20.length;if(0==_L10||_Lc){hide('pts_userlist','pts_userlistlabel','pts_choose_text','pts_invite_msg');if(_Lb){_L1d();}else hide('pts_invite_section');return;}show('pts_userlist','pts_userlistlabel','pts_choose_text');hide('pts_invite_section');if(_Lb)show('pts_invite_msg');var _L24='';if(0!=_L1f.length&&0!=_L20.length)_L24='<hr />';var _L25=_L20.join('')+_L24+_L1f.join('');$('pts_userlist').setContent(HTML(_L25));if((1==_L10)&&_L1e)DOM.find($('pts_userlist'),'input[type="checkbox"]').checked=true;};var _L13=function(){if(_L4){return _L19();}else if(_L7)return false;_L7=true;new AsyncRequest().setHandler(_L15).setErrorHandler(_L16).setTransportErrorHandler(_L16).setFinallyHandler(function(){_L7=false;}).setURI('/ajax/photos_tag_options.php').setData({pid:_L9,id:_L8,oid:_La}).setMethod('GET').setReadOnly(true).send();};var _L14=function(){_L5=_L4;if(!_Lf)return;for(var i=0,len=_Lf.length;i<len;i++)if(_Lf[i]['id']>0){_L5=_L5.filter(function(f){return _Lf[i]['id']!=f['id'];});}else _L5=_L5.filter(function(f){return _Lf[i]['id']!=f['id']||_Lf[i]['name'].toLowerCase()!=f['name'].toLowerCase();});};var _L15=function(_L1e){_L5=_L4=_L1e.getPayload();for(var i=0,len=_L4.length;i<len;i++)_L17(_L4[i]);_L19();};var _L16=function(_L1e){PhotoTagSelector.hide();ErrorDialog.showAsyncError(_L1e);};var _L17=function(_L1e){_L1e['flat_name']=typeahead_source.flatten_string(_L1e['name']);_L1e['fragment']=['<label><input type="checkbox" onclick="',sprintf('PhotoTagSelector._checkboxClick(this, %d, \'%s\')',_L1e['id'],escape_js_quotes(_L1e['name'])),'" />',htmlize(_L1e['name']),'</label>'].join('');};var _L18=function(_L1e){_L6.push(_L1e);};var _L19=function(){for(var i=0,len=_L6.length;i<len;i++)_L6[i]();_L6=[];};var _L1a=function(_L1e){switch(Event.getKeyCode(_L1e)){case KEYS.RETURN:_L1b();break;case KEYS.ESC:PhotoTagSelector.hide();break;default:setTimeout(_L12,0);}};var _L1b=function(){var id=0;var name='';var _L20='';if(''!=_L2.value.trim()){_L20=_L2.value.trim();name=_L1.value.trim();}else if(1==_L10){var _L21=DOM.find($('pts_userlist'),'input[type="checkbox"]');if(_L21.checked){return _L21.onclick();}else name=_L1.value.trim();}else name=_L1.value.trim();_L1c(id,name,_L20);};var _L1c=function(id,name,_L20){id=id||0;name=name||'';_L20=_L20||'';if(!name&&!id)return;_Ld(id,name,_L20);PhotoTagSelector.hide();if(id){for(var i=0,len=_L4.length;i<len;i++)if(_L4[i]['id']==id){_L4[i]['rel']=true;break;}}else if(!_L20){var _L23=false;for(var i=0,len=_L4.length;i<len;i++)if(!_L4[i].id&&_L4[i].name==name){_L4[i].rel=true;_L23=true;break;}if(!_L23){var _L24={name:name,rel:true,id:0};_L17(_L24);_L4.unshift(_L24);}}};var _L1d=function(){var _L1e=_L1.value.trim();var _L1f;if(_L1e){var _L20=_L1e.indexOf(' ');_L1f=_L20>-1?_L1e.substr(0,_L20):_L1e;}else _L1f=_tx("your friend");$('pts_invite_name').setContent(_L1f);show('pts_invite_section');};return {init:function(_L1e){if(_L3)return;_L3=true;_L0=$N('div',null,HTML(_L1e));_L0.id='photo_tag_selector';DOMScroll.getScrollRoot().appendChild(_L0);_L2=$('pts_invite_email');_L1=$('pts_name_input');_L1.onkeyup=_L1a;DOM.find(_L0,'input[name="tag"]').onclick=_L1b;DOM.find(_L0,'input[name="cancel"]').onclick=this.hide;},prime:function(){_L13();return this;},hide:function(){_Le();if(!_L3)return;_L0.style.display='none';_Ld=bagofholding;_Le=bagofholding;_L8=null;_L9=null;_La=null;_Lf=[];_L10=0;_L11();return this;},showAt:function(_L1e){_L1e.setElementPosition(_L0);_L0.style.display='block';_L18(_L14);_L18(_L12);_L18(function(){_L1.focus();});_L13();return this;},setTagCallback:function(_L1e){_Ld=_L1e;return this;},setHideCallback:function(_L1e){_Le=_L1e;return this;},setTaggedPeople:function(_L1e){_Lf=_L1e;return this;},setPhotoOwner:function(_L1e){_L8=_L1e;return this;},setPhotoId:function(_L1e){_L9=_L1e;return this;},setPhotoObjectId:function(_L1e){_La=_L1e;return this;},setAllowEmailTags:function(_L1e){_Lb=_L1e;return this;},enterInviteMode:function(){_Lc=true;hide('pts_userlist','pts_userlistlabel','pts_choose_text','pts_invite_msg');_L1d();if(_L1.value){var _L1e=DOM.find($('pts_invite_section'),'input[name="pts_invite_email"]');_L1e.focus();}else _L1.focus();return this;},exitInviteMode:function(){_Lc=false;hide('pts_invite_section');if(_Lb)show('pts_invite_msg');return this;},_checkboxClick:function(_L1e,id,name){if(!_L1e||!_L1e.checked)return;_L1c(id,name);}};}();function PhotoTagController(_L0){if(PhotoTagController._instances[_L0])return PhotoTagController._instances[_L0];copy_properties(this,{photoElementId:_L0,photoOwnerId:null,photoId:null,photoObjectId:null,_taggingEnabled:false,_tagCallbackFn:bagofholding,_autoSubmitTags:true,viewerObject:PhotoTagViewer.getInstance(_L0)});this._getPhotoElement=bind(null,ge,_L0);this._destruct=function(){PhotoTagSelector.hide();this.viewerObject._destruct();delete PhotoTagController._instances[_L0];};this._wait_for_load=function(_L2){_L2.deferUntil(image_has_loaded.bind(this,this._getPhotoElement()),100);};if(!this._getPhotoElement())throw new Error('No images with the id `'+_L0+'\' '+'found on the page.  PhotoTagController Abort.');onunloadRegister(bind(this,this._destruct));var _L1=this._getPhotoElement();_L1.onclick=chain(bind(this,this._photoClick),_L1.onclick);PhotoTagController._instances[_L0]=this;}copy_properties(PhotoTagController,{_instances:{},getInstance:function(_L0){return PhotoTagController._instances[_L0];}});copy_properties(PhotoTagController.prototype,{setPhotoData:function(_L0,_L1){this.photoOwnerId=_L0;this.photoId=_L1;PhotoTagSelector.hide();this.viewerObject.setPhotoData(_L0,_L1);return this;},setPhotoObjectId:function(_L0){this.photoObjectId=_L0;return this;},setMinTagDistance:function(_L0){this.viewerObject.setMinTagDistance(_L0);return this;},enableTagging:function(_L0,_L1){if(!this._getPhotoElement())return this._destruct();this.viewerObject.enableTagging();this._taggingEnabled=true;this._tagCallbackFn=_L0||bagofholding;this._autoSubmitTags=(_L1===undefined)||_L1;this._getPhotoElement().style.cursor='crosshair';PhotoTagSelector.setPhotoOwner(this.photoOwnerId).setPhotoId(this.photoId).setPhotoObjectId(this.photoObjectId).prime();return this;},disableTagging:function(){this.viewerObject.disableTagging();if(!this._getPhotoElement())return this._destruct();this._taggingEnabled=false;this._tagCallbackFn=bagofholding;this._autoSubmitTags=true;this._getPhotoElement().style.cursor='';PhotoTagSelector.hide();return this;},_photoClick:function(_L0){if(!this._getPhotoElement())return this._destruct();if(!this._taggingEnabled)return true;var _L1=PhotoTag.tagsForPhoto(this.photoId,this.photoOwnerId);if(PhotoTag.MAX_TAGS_PER_PHOTO<=_L1.length){new ErrorDialog().showError(_tx("Too Many Tags"),_tx("A photo may only have up to {limit} tags. To add a new tag, you must first remove one of the existing tags on the photo.",{limit:PhotoTag.MAX_TAGS_PER_PHOTO}));return $E(_L0).kill();}PhotoTagSelector.hide();var _L2=Vector2.getEventPosition(_L0);var _L3=Vector2.getElementPosition(this._getPhotoElement());var _L4=Vector2.getElementDimensions(this._getPhotoElement());var _L5=_L2.sub(_L3);var tag=new PhotoTag(100*_L5.x/_L4.x,100*_L5.y/_L4.y,this.photoOwnerId,this.photoId);this.viewerObject.showTag(tag);var _L7=Vector2.getElementPosition(this.viewerObject.tagFrame);if(_L5.x>(_L4.x/2)||_L4.x<300){_L7=_L7.sub(210,0);}else{var _L8=Vector2.getElementDimensions(this.viewerObject.tagFrame);_L7=_L7.add(_L8.x+10,0);}var _L9=[];for(var i=0,len=_L1.length;i<len;i++)_L9.push({name:_L1[i].getText(),id:_L1[i].getTaggeeId()});PhotoTagSelector.setTagCallback(bind(this,this._photoTagCallback,tag)).setHideCallback(bind(this.viewerObject,this.viewerObject.hideTag)).setPhotoOwner(this.photoOwnerId).setPhotoId(this.photoId).setPhotoObjectId(this.photoObjectId).setTaggedPeople(_L9).showAt(_L7);return $E(_L0).kill();},_photoTagCallback:function(tag,id,_L2,_L3){if(id)tag.setTaggeeId(id);if(_L2)tag.setTaggeeName(_L2);if(_L3)tag.setTaggeeEmail(_L3);if(this._autoSubmitTags){tag.submit(this._tagCallbackFn);}else{tag.setLocalSave();this._tagCallbackFn(tag,{});}},_isPhotoCropOn:function(){return window['photocrop']&&window['photocrop'].instance&&true;}});

if (window.Bootloader) { Bootloader.done(["js\/5axkticoym0w0oss.pkg.js"]); }