/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  December 15th 2009 4:37:36 PM PST                            */
/*      Machine:  10.16.140.108                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/et2u8jb6pkowggso.pkg.js h:gldaexeu                        */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/et2u8jb6pkowggso.pkg.js                                   */

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


function EventController(eventResponderObject){copy_properties(this,{_queue:[],_ready:false,_responder:eventResponderObject});};copy_properties(EventController.prototype,{startQueue:function(){this._ready=true;this.dispatchEvents();return this;},pauseQueue:function(){this._ready=false;return this;},addEvent:function(event){event=event.toLowerCase();var args=[];for(var ii=1;ii<arguments.length;ii++){args.push(arguments[ii]);}
this._queue.push({type:event,args:args});if(this._ready){this.dispatchEvents();}
return false;},dispatchEvents:function(){if(!this._responder){throw new Error('No event responder.');}
for(var ii=0;ii<this._queue.length;ii++){var evtName='on'+this._queue[ii].type;if(typeof(this._responder[evtName])!='function'&&typeof(this._responder[evtName])!='null'){throw new Error('No event handler.');}else{if(this._responder[evtName]){this._responder[evtName].apply(this._responder,this._queue[ii].args);}}}
this._queue=[];}});

var Configurable={getOption:function(opt){if(typeof(this.option[opt])=='undefined'){Util.warn('Failed to get option %q; it does not exist.',opt);return null;}
return this.option[opt];},setOption:function(opt,v){if(typeof(this.option[opt])=='undefined'){Util.warn('Failed to set option %q; it does not exist.',opt);}else{this.option[opt]=v;}
return this;},getOptions:function(){return this.option;}};

function Task(taskFunction,taskFunctionIsSynchronous){copy_properties(this,{task:taskFunction,option:{synchronous:!!taskFunctionIsSynchronous},status:Task.WAITING,result:null,queue:null});}
copy_properties(Task,{WAITING:0,READY:1,RUNNING:2,DONE:3,ERROR:4});copy_properties(Task.prototype,Configurable);copy_properties(Task.prototype,{run:function(){this.status=Task.RUNNING;try{var result=this.task();}catch(exception){this.status=Task.ERROR;exception._task=this;throw exception;}
if(this.getOption('synchronous')){this.didComplete(result);}},didComplete:function(result){this.result=result;this.status=Task.DONE;if(this.queue){this.queue.didCompleteTask(this);}
return this;}});function TaskQueue(){copy_properties(this,{queue:[],executingTasks:0,executionDepth:0,option:{synchronous:true,concurrency:2}});};copy_properties(TaskQueue.prototype,Configurable);copy_properties(TaskQueue.prototype,{addTask:function(task){this.queue.push(task);task.queue=this;return task;},didCompleteTask:function(task){this.executingTasks--;this.reapQueue();if(!this.executionDepth){this.start();}},runTask:function(task){this.executingTasks++;if(this.getOption('synchronous')){try{task.run();}catch(exception){Util.error('Exception thrown while running task: %x.',exception);this.didCompleteTask();}}else{setTimeout(bind(task,'run'),10);}},reapQueue:function(){var status;var ii,len;for(ii=0,len=this.queue.length;ii<len;ii++){status=this.queue[ii].status;if(status!=Task.DONE&&status!=Task.ERROR){break;}}
if(ii){this.queue=this.queue.slice(ii);}},start:function(){this.executionDepth++;while(this.executingTasks<this.getOption('concurrency')){for(var ii=0,len=this.queue.length;ii<len;ii++){if(this.queue[ii].status==Task.READY){this.runTask(this.queue[ii]);break;}}
if(ii==len){break;}}
this.executionDepth--;},ready:function(n){n=n||1;for(var ii=0,len=this.queue.length;ii<len;ii++){if(this.queue[ii].status==Task.WAITING){this.queue[ii].status=Task.READY;if(!(--n)){break;}}}
this.start();}});

var PhotostreamConstants={ShowPhoto:'photostream/showPhoto'};

function Photostream(img,next_url,is_search,data,uid,pid,pos,count,page,log_actions,payload,ads_refresh_min_interval){Photostream.instance=this;if(next_url){(new Image()).src=next_url;}
if(ua.safari()<500||ua.firefox()<2){return;}
copy_properties(this,{data:copy_properties(data,{async:true}),seq:0,pid:pid,img:img,minseq:0,isSearch:is_search});copy_properties(this,{error:0,album:new Array(count),has_moved:false,jumps:{},unseen:null,cursor:null,is_rendered:true,queue:new TaskQueue(),loads:[],pagesize:20,fetched:{},pending:(payload?1:0),readied:false,lastTimeout:null,slideshowSpeed:3000,slideshowActive:false,slideshowEventsInited:false,photoLoadTimeout:null});copy_properties(this,{displayPosition:$('photo_count'),displayPhototags:$('phototags'),displayShare:$('photo_share'),displayComments:$('photocomment'),displayNext:ge('photo_form_next'),displayBadge:$('photo_badge'),displayActions:$('photoactions'),photolink:$('myphotolink'),displayLoad:$('load_indicator'),displayContext:$('photoinalbum'),displayPublicLink:ge('public_link_uri'),displayStartShow:ge('photo_start_show'),displayStopShow:ge('photo_stop_show'),displayCaption:DOM.find($('photocaption_parent'),'div.photocaption_text')});copy_properties(this,{lastAdsRefreshTime:(new Date()).getTime(),adsRefreshMinInterval:ads_refresh_min_interval});var next=this.onnext.bind(this);var prev=this.onprev.bind(this);var play=this.onplay.bind(this);var stop=this.onstop.bind(this);(ge('photonav_next')||{}).onclick=next;(ge('photonav_prev')||{}).onclick=prev;if(this.displayStartShow){this.displayStartShow.onclick=play;}
if(this.displayStopShow){this.displayStopShow.onclick=stop;}
this.img.onclick=chain(this.img.onclick,next);this.img.onload=null;if(ua.ie()<7){this.img.galleryimg="no";}
KeyEventController.registerKey('RIGHT',next);KeyEventController.registerKey('LEFT',prev);this.cursor=pos;this.requestPage(page);if(log_actions){onunloadRegister(bind(this,function(type){scribe_log(type?'photostream':'photostream_ajax',this.seq);},payload!=undefined),true);}
PageTransitions.registerHandler(bind(this,'pageTransitionHandler'));this.orig_params=URI.getRequestURI().getQueryData();};copy_properties(Photostream.prototype,{debug:bagofholding,setupCaptions:function(uid,pid,typeahead){var parent=$('photocaption_parent');if(Photocaption){var capOptions={typeaheadSource:typeahead,successCallback:this.setDataFromCaption.bind(this),beginEditCallback:this.stopSlideshow.bind(this)};var info=this.album[this.cursor];var id=info?info.id:uid;var pid=info?info.pid:pid;this.caption=new Photocaption(parent,id,pid,capOptions);}},requestPage:function(page){if(this.fetched[page]){return;}
this.fetched[page]=true;this.pending++;new AsyncRequest().setURI(this.isSearch?'/photo_search.php':'/album.php').setMethod('GET').setReadOnly(true).setData(copy_properties(this.data,{page:page})).setHandler(bind(this,'didGetAlbumResponse',page)).setErrorHandler(bind(this,'didGetAlbumError')).setTransportErrorHandler(bind(this,'didGetAlbumError')).send();},checkAndRefreshAds:function(){var now=(new Date()).getTime();if(now-this.lastAdsRefreshTime>=this.adsRefreshMinInterval){ads_refresh('','/photo.php',null,null,true);this.lastAdsRefreshTime=now;}},onnext:function(e){var next_cursor=(this.cursor+1)%this.album.length;if(this.slideshowActive){clearTimeout(this.lastTimeout);}
this.checkAndRefreshAds();if(!this.hideKeyPress(e)&&this.showPhoto(next_cursor)){return $E(e).kill();}},hideKeyPress:function(e){if(this.caption&&this.caption.mentionsIsFocused()){event=$E(e);var code=event?event_get_keypress_keycode(event):-1;switch(code){case KEYS.RIGHT:case KEYS.LEFT:return true;}}
return false;},setDataFromCaption:function(payload){this.album[this.cursor].caption=payload.rendered;this.album[this.cursor].caption_plaintext=payload.plaintext;},slideshowTimeoutCallback:function(){var next_cursor=(this.cursor+1)%this.album.length;if(this.slideshowActive){if(this.album[next_cursor]){this.showPhoto(next_cursor);}else{this.requestPage(1+Math.floor(next_cursor/this.pagesize));this.slideshowGoNext(500);}}},onprev:function(e){var prev_cursor=((this.cursor-1)+this.album.length)%this.album.length;this.checkAndRefreshAds();if(!this.hideKeyPress(e)&&this.showPhoto(prev_cursor)){return $E(e).kill();}},onplay:function(e){this.slideshowActive=true;if(!this.slideshowEventsInited){Event.listen(window,'mousedown',this.onSlideshowInputEvent.bind(this));Event.listen(window,'keypress',this.onSlideshowInputEvent.bind(this));this.slideshowEventsInited=true;}
this.showSlideshowControls();this.slideshowGoNext(this.slideshowSpeed);return false;},onstop:function(e){this.stopSlideshow();return $E(e).kill();},stopSlideshow:function(){if(this.slideshowEventsInited&&this.displayStartShow){this.slideshowActive=false;clearTimeout(this.lastTimeout);this.hideSlideshowControls();}},onSlideshowInputEvent:function(e){if(!this.slideshowActive||!e){return;}
var target=e.getTarget();var killShow=true;switch(target){case'my_photo':case'photonav_next':case'photonav_prev':case'photo_start_show':case'photo_stop_show':killShow=false;break;default:break;}
if(killShow){this.stopSlideshow();clearTimeout(this.lastTimeout);}
return true;},slideshowGoNext:function(interval){clearTimeout(this.lastTimeout);this.lastTimeout=setTimeout(this.slideshowTimeoutCallback.bind(this),interval);},showSlideshowControls:function(){CSS.removeClass(this.displayStopShow,'hidden_elem');CSS.addClass(this.displayStartShow,'hidden_elem');},hideSlideshowControls:function(){CSS.addClass(this.displayStopShow,'hidden_elem');CSS.removeClass(this.displayStartShow,'hidden_elem');},readPhotoState:function(){if(this.is_rendered&&this.album[this.cursor]){if(ua.safariPreWebkit()){this.album[this.cursor].tags=this.displayPhototags.innerHTML.replace(/\\\//g,'/');}else{this.album[this.cursor].tags=this.displayPhototags.innerHTML;}
if(this.displayComments){this.album[this.cursor].comments=this.displayComments.innerHTML;}}},showPhoto:function(index){if(this.error){return false;}
if(this.caption&&this.caption.isUpdating()){return true;}
var already_waiting=this.has_moved&&!this.album[this.cursor];this.has_moved=true;this.setCursor(index);var photo_info=this.album[index];if(photo_info){Arbiter.inform(PhotostreamConstants.ShowPhoto,{'node':{'href':URI.getRequestURI().toString()},'pid':photo_info.pid,'aid':photo_info.id,'ss':this.slideshowActive});goURI(URI.getRequestURI().addQueryData({pid:photo_info.pid,id:photo_info.id}).removeQueryData('alert'));}else{if(!already_waiting){this.showLoadIndicator();this.prepareToLeavePhoto();}
this.requestPage(1+parseInt(index/this.pagesize));}
return true;},prepareToLeavePhoto:function(){if(!this.readied){this.readied=true;var stepsAhead=env_get('ps_rate')||(5);this.queue.setOption('concurrency',stepsAhead).ready(stepsAhead);}
if(ge('changessaved')){DOM.remove(ge('changessaved'));}
if(ge('photocrop_error')){DOM.remove(ge('photocrop_error'));}
PhotoPageTags.resetInstructions();},setCursor:function(index){if(index===this.cursor){return;}
this.readPhotoState();this.is_rendered=false;this.cursor=index;this.updateCountText();},updateCountText:function(){var pos=_tx("Photo {photo-number} of {total-count}",{"photo-number":this.cursor+1,"total-count":this.album.length});this.displayPosition&&DOM.setContent(this.displayPosition,HTML(pos));},showCursorPhotoWithInfo:function(){this.prepareToLeavePhoto();var info=this.album[this.cursor];var img=document.createElement('img');copy_properties(img.style,{display:'none'});if(!info.seen){var hi_bound=(parseInt(this.cursor/this.pagesize)+1)*this.pagesize;hi_bound=Math.min(hi_bound,this.album.length);var near_edge=((hi_bound-this.cursor)<=3);info.seen=true;--this.unseen;if(near_edge&&!this.pending){var cur_page=parseInt(this.cursor/this.pagesize)+1;var max_page=parseInt((this.album.length-1)/this.pagesize)+1;var get_page=null;for(ii=cur_page+1;ii<=max_page;ii++){if(!this.fetched[ii]){get_page=ii;break;}}
if(get_page===null){for(ii=1;ii<cur_page;ii++){if(!this.fetched[ii]){get_page=ii;break;}}}
if(get_page!==null){this.requestPage(get_page);}}}
if(!this.photoLoadTimeout){this.photoLoadTimeout=setTimeout(this.showLoadIndicator.bind(this),750);}
img.seq=++this.seq;img.onload=bind(this,'renderPhoto',img,info);img.src=info.src;},renderPhoto:function(img,info){if(img.seq<this.minseq){delete img;return;}
this.hideLoadIndicator();this.minseq=img.seq;var t=copy_properties({},{id:this.img.id,onmousedown:this.img.onmousedown,onmouseup:this.img.onmouseup,onclick:this.img.onclick});if(window['photocrop']){photocrop.destroy();}
img.style.display='';this.img.parentNode.appendChild(img);img.style.cursor=this.img.style.cursor;DOM.remove(this.img);this.img=img;copy_properties(this.img,t);this.displayCaption&&set_inner_html(this.displayCaption,HTML(info.caption));this.displayPhototags&&set_inner_html(this.displayPhototags,info.tags);this.displayComments&&set_inner_html(this.displayComments,info.comments);this.displayBadge&&set_inner_html(this.displayBadge,info.badge);this.displayActions&&set_inner_html(this.displayActions,info.actions);this.displayContext&&set_inner_html(this.displayContext,info.context_info);this.displayPublicLink&&set_inner_html(this.displayPublicLink,info.public_link);if(this.caption){this.caption.setCaptionData(info.id,info.pid,info.caption_plaintext);}
this.is_rendered=true;if(this.displayShare){this.displayShare.onclick=bind(null,share_internal_config,info.share);}
PhotoTagController.getInstance('myphoto').setPhotoData(info.id,info.pid);if(this.slideshowActive){animation(this.img).from('opacity',0).to('opacity',1).duration(300).ondone(this.slideshowGoNext.bind(this,this.slideshowSpeed)).go();}
this.queue.ready();},didGetAlbumResponse:function(page,asyncResponse){this.pending--;var payload=asyncResponse.getPayload();var waiting=(this.has_moved&&this.cursor!==null&&!this.album[this.cursor]);var img,task,load,pos,photo_data=payload.data;for(var ii=0;ii<photo_data.length;++ii){data=photo_data[ii];pos=(this.pagesize*(page-1))+ii;if(this.cursor===null&&data.pid==this.pid){this.cursor=pos;}
data.pos=pos;data.seen=false;this.album[pos]=data;this.jumps[data.pid]=pos;img=new Image();load=bind(img,function(src){this.src=src;},data.src);task=new Task(load);img.onload=task.didComplete.bind(task);this.queue.addTask(task);}
this.unseen+=photo_data.length;if(payload.album_count){this.album.length=payload.album_count;this.updateCountText();}
if(waiting){this.showPhoto(this.cursor);}},didGetAlbumError:function(asyncResponse){Util.error(asyncResponse.getErrorDescription());this.error=asyncResponse.getError();ErrorDialog.showAsyncError(asyncResponse);},pageTransitionHandler:function(uri){var params=uri.getQueryData();if(uri.getPath()=='/photo.php'){for(var v in this.orig_params){if(v!='pid'&&(!this.isSearch||(v!='id'&&v!='psids'))&&this.orig_params[v]!=params[v]){return false;}}
if(params.alert!==undefined){return false;}
pid=parseInt(params.pid,10);if(this.jumps[pid]!==undefined){this.setCursor(this.jumps[pid]);this.showCursorPhotoWithInfo();PageTransitions.transitionComplete();return true;}}
return false;},showLoadIndicator:function(){CSS.addClass(this.displayLoad,'loading');animation(this.displayLoad).to('opacity',0).duration(0).go().to('opacity',1).duration(200).go();animation(this.img).to('opacity',0).duration(200).go();return this;},hideLoadIndicator:function(){if(this.photoLoadTimeout){clearTimeout(this.photoLoadTimeout);this.photoLoadTimeout=null;}
animation(this.img).to('opacity',1).duration(0).go();CSS.removeClass(this.displayLoad,'loading');return this;}});function photo_delete(href){var async=new AsyncRequest().setMethod('GET').setReadOnly(true).setURI(href);new Dialog().setAsync(async).show();return false;}
function photo_fax(id,pid){new Dialog().setAsync(new AsyncRequest('/ajax/photos/fax.php').setData({id:id,pid:pid})).show();return false;}
function photo_remove_profile_picture(profile_id){function remove_confirm_handler(){var async=new AsyncRequest().setURI('/ajax/profile/picture/remove.php').setData({remove:true,id:profile_id}).setHandler(bind(document.location,document.location.reload)).send();}
new Dialog().setTitle(_tx("Remove Picture?")).setBody(_tx("Are you sure you want to remove this picture?")).setButtons(Dialog.OK_AND_CANCEL).setHandler(remove_confirm_handler).show();return false;}

PhotoTagSelector=function(){var _selectorDiv;var _taggeeNameInput;var _emailInput;var _inited=false;var _originalFriendData=null;var _friendData=[];var _friendDataCallbacks=[];var _pendingAsync=false;var _photoOwner=null;var _photoId=null;var _photoObjectId=null;var _allowEmailTags=false;var _inviteMode=false;var _tagCallback=bagofholding;var _hideCallback=bagofholding;var _taggedPeople=[];var _totalNumMatches=0;var _clear=function(){_taggeeNameInput.value='';_emailInput.value='';PhotoTagSelector.exitInviteMode();};var _populate=function(){if(!_inited){return;}
var inputText=_taggeeNameInput.value.toLowerCase().trim();inputText=typeahead_source.flatten_string(inputText);var matches=[];var relevantMatches=[];for(var i=0,len=_friendData.length;i<len;i++){var friend=_friendData[i];if(!inputText||-1!=friend['flat_name'].indexOf(inputText)){(friend['rel']?relevantMatches:matches).push(friend['fragment']);}}
_totalNumMatches=matches.length+relevantMatches.length;if(0==_totalNumMatches||_inviteMode){hide('pts_userlist','pts_userlistlabel','pts_choose_text','pts_invite_msg');if(_allowEmailTags){_showInviteForm();}else{hide('pts_invite_section');}
return;}
show('pts_userlist','pts_userlistlabel','pts_choose_text');hide('pts_invite_section');if(_allowEmailTags){show('pts_invite_msg');}
var separator='';if(0!=matches.length&&0!=relevantMatches.length){separator='<hr />';}
var markup=relevantMatches.join('')+separator+matches.join('');$('pts_userlist').setContent(HTML(markup));if((1==_totalNumMatches)&&inputText){DOM.find($('pts_userlist'),'input[type="checkbox"]').checked=true;}};var _getFriendData=function(){if(_originalFriendData){return _processCallbacks();}else if(_pendingAsync){return false;}
_pendingAsync=true;new AsyncRequest().setHandler(_getFriendDataHandler).setErrorHandler(_getFriendDataErrorHandler).setTransportErrorHandler(_getFriendDataErrorHandler).setFinallyHandler(function(){_pendingAsync=false;}).setURI('/ajax/photos_tag_options.php').setData({pid:_photoId,id:_photoOwner,oid:_photoObjectId}).setMethod('GET').setReadOnly(true).send();};var _removeTaggedPeople=function(){_friendData=_originalFriendData;if(!_taggedPeople){return;}
for(var i=0,len=_taggedPeople.length;i<len;i++){if(_taggedPeople[i]['id']>0){_friendData=_friendData.filter(function(f){return _taggedPeople[i]['id']!=f['id'];});}else{_friendData=_friendData.filter(function(f){return _taggedPeople[i]['id']!=f['id']||_taggedPeople[i]['name'].toLowerCase()!=f['name'].toLowerCase();});}}};var _getFriendDataHandler=function(response){_friendData=_originalFriendData=response.getPayload();for(var i=0,len=_originalFriendData.length;i<len;i++){_enhanceFriend(_originalFriendData[i]);}
_processCallbacks();};var _getFriendDataErrorHandler=function(response){PhotoTagSelector.hide();ErrorDialog.showAsyncError(response);};var _enhanceFriend=function(friend){friend['flat_name']=typeahead_source.flatten_string(friend['name']);friend['fragment']=['<label><input type="checkbox" onclick="',sprintf('PhotoTagSelector._checkboxClick(this, %d, \'%s\')',friend['id'],escape_js_quotes(friend['name'])),'" />',htmlize(friend['name']),'</label>'].join('');};var _addCallback=function(newCallback){_friendDataCallbacks.push(newCallback);};var _processCallbacks=function(){for(var i=0,len=_friendDataCallbacks.length;i<len;i++){_friendDataCallbacks[i]();}
_friendDataCallbacks=[];};var _keyUpHandler=function(event){switch(event_get_keypress_keycode(event)){case KEYS.RETURN:_blankSubmit();break;case KEYS.ESC:PhotoTagSelector.hide();break;default:setTimeout(_populate,0);}};var _blankSubmit=function(){var id=0;var name='';var email='';if(''!=_emailInput.value.trim()){email=_emailInput.value.trim();name=_taggeeNameInput.value.trim();}else if(1==_totalNumMatches){var singleOption=DOM.find($('pts_userlist'),'input[type="checkbox"]');if(singleOption.checked){return singleOption.onclick();}else{name=_taggeeNameInput.value.trim();}}else{name=_taggeeNameInput.value.trim();}
_select(id,name,email);};var _select=function(id,name,email){id=id||0;name=name||'';email=email||'';if(!name&&!id){return;}
_tagCallback(id,name,email);PhotoTagSelector.hide();if(id){for(var i=0,len=_originalFriendData.length;i<len;i++){if(_originalFriendData[i]['id']==id){_originalFriendData[i]['rel']=true;break;}}}else if(!email){var found=false;for(var i=0,len=_originalFriendData.length;i<len;i++){if(!_originalFriendData[i].id&&_originalFriendData[i].name==name){_originalFriendData[i].rel=true;found=true;break;}}
if(!found){var newEntry={name:name,rel:true,id:0};_enhanceFriend(newEntry);_originalFriendData.unshift(newEntry);}}};var _showInviteForm=function(){var inputText=_taggeeNameInput.value.trim();var firstName;if(inputText){var spaceIndex=inputText.indexOf(' ');firstName=spaceIndex>-1?inputText.substr(0,spaceIndex):inputText;}else{firstName=_tx("your friend");}
$('pts_invite_name').setContent(firstName);show('pts_invite_section');};return{init:function(markup){if(_inited){return;}
_inited=true;_selectorDiv=$N('div',null,HTML(markup));_selectorDiv.id='photo_tag_selector';DOMScroll.getScrollRoot().appendChild(_selectorDiv);_emailInput=$('pts_invite_email');_taggeeNameInput=$('pts_name_input');_taggeeNameInput.onkeyup=_keyUpHandler;DOM.find(_selectorDiv,'input[name="tag"]').onclick=_blankSubmit;DOM.find(_selectorDiv,'input[name="cancel"]').onclick=this.hide;},prime:function(){_getFriendData();return this;},hide:function(){_hideCallback();if(!_inited){return;}
_selectorDiv.style.display='none';_tagCallback=bagofholding;_hideCallback=bagofholding;_photoOwner=null;_photoId=null;_photoObjectId=null;_taggedPeople=[];_totalNumMatches=0;_clear();return this;},showAt:function(positionVect){positionVect.setElementPosition(_selectorDiv);_selectorDiv.style.display='block';_addCallback(_removeTaggedPeople);_addCallback(_populate);_addCallback(function(){_taggeeNameInput.focus();});_getFriendData();return this;},setTagCallback:function(newCallback){_tagCallback=newCallback;return this;},setHideCallback:function(newCallback){_hideCallback=newCallback;return this;},setTaggedPeople:function(taggedPeople){_taggedPeople=taggedPeople;return this;},setPhotoOwner:function(photoOwner){_photoOwner=photoOwner;return this;},setPhotoId:function(photoId){_photoId=photoId;return this;},setPhotoObjectId:function(photoObjectId){_photoObjectId=photoObjectId;return this;},setAllowEmailTags:function(allowEmailTags){_allowEmailTags=allowEmailTags;return this;},enterInviteMode:function(){_inviteMode=true;hide('pts_userlist','pts_userlistlabel','pts_choose_text','pts_invite_msg');_showInviteForm();if(_taggeeNameInput.value){var invite_email_field=DOM.find($('pts_invite_section'),'input[name="pts_invite_email"]');invite_email_field.focus();}else{_taggeeNameInput.focus();}
return this;},exitInviteMode:function(){_inviteMode=false;hide('pts_invite_section');if(_allowEmailTags){show('pts_invite_msg');}
return this;},_checkboxClick:function(checkbox,id,name){if(!checkbox||!checkbox.checked){return;}
_select(id,name);}};}();function PhotoTagController(photoElementId){if(PhotoTagController._instances[photoElementId]){return PhotoTagController._instances[photoElementId];}
copy_properties(this,{minTagDistance:83,photoOwnerId:null,photoId:null,photoObjectId:null,tagShowCallback:bagofholding,tagHideCallback:bagofholding,showingTag:null,tagFrame:null,nameFrame:null,_taggingEnabled:false,_tagCallbackFn:bagofholding,_autoSubmitTags:true});this._getPhotoElement=bind(null,ge,photoElementId);this._destruct=function(){mousemove_ref.remove();this.hideTag();this.tagHideCallback();PhotoTagSelector.hide();delete PhotoTagController._instances[photoElementId];};this._wait_for_load=function(callback){callback.deferUntil(image_has_loaded.bind(this,this._getPhotoElement()),100);};if(!this._getPhotoElement()){throw new Error('No images with the id `'+photoElementId+'\' '+'found on the page.  PhotoTagController Abort.');}
var listen_func=bind(this,this._photoMouseMove);var mousemove_ref=Event.listen(document,'mousemove',listen_func);onunloadRegister(bind(this,this._destruct));var photo=this._getPhotoElement();photo.onclick=chain(bind(this,this._photoClick),photo.onclick);PhotoTagController._instances[photoElementId]=this;}
copy_properties(PhotoTagController,{_instances:{},getInstance:function(photoElementId){return PhotoTagController._instances[photoElementId];}});copy_properties(PhotoTagController.prototype,{setPhotoData:function(photoOwnerId,photoId){this.photoOwnerId=photoOwnerId;this.photoId=photoId;PhotoTagSelector.hide();this.hideTag();this.tagHideCallback();return this;},setPhotoObjectId:function(photoObjectId){this.photoObjectId=photoObjectId;return this;},setMinTagDistance:function(minTagDistance){this.minTagDistance=minTagDistance;return this;},registerTagHover:function(showFunction,hideFunction){if(!showFunction&&!hideFunction){this.tagShowCallback=bind(this,this.showTagText);this.tagHideCallback=bind(this,this.hideTagText);}else{this.tagShowCallback=showFunction;this.tagHideCallback=hideFunction;}
return this;},enableTagging:function(tagCallback,autoSubmit){if(!this._getPhotoElement()){return this._destruct();}
this._taggingEnabled=true;this._tagCallbackFn=tagCallback||bagofholding;this._autoSubmitTags=(autoSubmit===undefined)||autoSubmit;this._getPhotoElement().style.cursor='crosshair';PhotoTagSelector.setPhotoOwner(this.photoOwnerId).setPhotoId(this.photoId).setPhotoObjectId(this.photoObjectId).prime();return this;},disableTagging:function(){if(!this._getPhotoElement()){return this._destruct();}
this._taggingEnabled=false;this._tagCallbackFn=bagofholding;this._autoSubmitTags=true;this._getPhotoElement().style.cursor='';PhotoTagSelector.hide();return this;},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 innerFrame=document.createElement('div');innerFrame.style.width=(2*this.minTagDistance)+'px';innerFrame.style.height=(2*this.minTagDistance)+'px';CSS.addClass(innerFrame,'photo_tag_frame_inside');this.tagFrame=$N('div',null,innerFrame);CSS.addClass(this.tagFrame,'photo_tag_frame');this.tagFrame.onclick=bind(this,this._photoClick);DOMScroll.getScrollRoot().appendChild(this.tagFrame);}
var imagePosition=Vector2.getElementPosition(this._getPhotoElement());var imageDimensions=Vector2.getElementDimensions(this._getPhotoElement());var tagPosition=tag.absoluteCenter(imageDimensions.x,imageDimensions.y);var adjustedTagInfo=this._calculateWithinBounds(tagPosition,2*this.minTagDistance,this._getPhotoElement());var tagDimensions=new Vector2(adjustedTagInfo.size,adjustedTagInfo.size);var tagOffset=tagDimensions.mul(0.5,0.5);tagDimensions.setElementDimensions(DOM.find(this.tagFrame,'div.photo_tag_frame_inside'));new Vector2(-10000,-100000,'document').setElementPosition(this.tagFrame);show(this.tagFrame);var border=Vector2.getElementDimensions(this.tagFrame).sub(adjustedTagInfo.size,adjustedTagInfo.size).mul(0.5,0.5);imagePosition.add(adjustedTagInfo.tagPosition).sub(tagOffset).sub(border).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 imagePosition=Vector2.getElementPosition(this._getPhotoElement());var imageDimensions=Vector2.getElementDimensions(this._getPhotoElement());var tagPosition=tag.absoluteCenter(imageDimensions.x,imageDimensions.y);var adjustedTagInfo=this._calculateWithinBounds(tagPosition,2*this.minTagDistance,this._getPhotoElement());var textDimensions=Vector2.getElementDimensions(this.nameFrame);var textOffset=new Vector2(textDimensions.x/2,8+textDimensions.y-adjustedTagInfo.size/2);imagePosition.add(adjustedTagInfo.tagPosition).sub(textOffset).setElementPosition(this.nameFrame);show(this.nameFrame);},hideTagText:function(){if(this.nameFrame){DOM.remove(this.nameFrame);}
this.nameFrame=null;},_forceWithinBounds:function(tagPosition,minPadding,imageDimensions){tagPosition=tagPosition.sub(0,0);if(tagPosition.x<minPadding){tagPosition.x=Math.min(minPadding,imageDimensions.x);}else if(tagPosition.x>imageDimensions.x-minPadding){tagPosition.x=Math.max(0,imageDimensions.x-minPadding);}
if(tagPosition.y<minPadding){tagPosition.y=Math.min(minPadding,imageDimensions.y);}else if(tagPosition.y>imageDimensions.y-minPadding){tagPosition.y=Math.max(0,imageDimensions.y-minPadding);}
return tagPosition;},_calculateWithinBounds:function(tagPosition,desiredSize,image){var imagePosition=Vector2.getElementPosition(image);var imageDimensions=Vector2.getElementDimensions(image);var left=Math.max(tagPosition.x-desiredSize/2,0);var right=Math.min(tagPosition.x+desiredSize/2,imageDimensions.x);var top=Math.max(tagPosition.y-desiredSize/2,0);var bottom=Math.min(tagPosition.y+desiredSize/2,imageDimensions.y);var tagPosition=new Vector2((right+left)/2,(top+bottom)/2);var size=Math.min(right-left,bottom-top);return{tagPosition:tagPosition,size:size};},_photoClick:function(event){if(!this._getPhotoElement()){return this._destruct();}
if(!this._taggingEnabled){return true;}
var tags=PhotoTag.tagsForPhoto(this.photoId,this.photoOwnerId);if(PhotoTag.MAX_TAGS_PER_PHOTO<=tags.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(event).kill();}
PhotoTagSelector.hide();var mousePosition=Vector2.getEventPosition(event);var imagePosition=Vector2.getElementPosition(this._getPhotoElement());var imageDimensions=Vector2.getElementDimensions(this._getPhotoElement());var mouseRelPosition=mousePosition.sub(imagePosition);var tag=new PhotoTag(100*mouseRelPosition.x/imageDimensions.x,100*mouseRelPosition.y/imageDimensions.y,this.photoOwnerId,this.photoId);this.showTag(tag);var selectorPosition=Vector2.getElementPosition(this.tagFrame);if(mouseRelPosition.x>(imageDimensions.x/2)||imageDimensions.x<300){selectorPosition=selectorPosition.sub(210,0);}else{var tagBoxDims=Vector2.getElementDimensions(this.tagFrame);selectorPosition=selectorPosition.add(tagBoxDims.x+10,0);}
var simpleList=[];for(var i=0,len=tags.length;i<len;i++){simpleList.push({name:tags[i].getText(),id:tags[i].getTaggeeId()});}
PhotoTagSelector.setTagCallback(bind(this,this._photoTagCallback,tag)).setHideCallback(bind(this,this.hideTag,tag)).setPhotoOwner(this.photoOwnerId).setPhotoId(this.photoId).setPhotoObjectId(this.photoObjectId).setTaggedPeople(simpleList).showAt(selectorPosition);return $E(event).kill();},_photoTagCallback:function(tag,id,name,email){if(id){tag.setTaggeeId(id);}
if(name){tag.setTaggeeName(name);}
if(email){tag.setTaggeeEmail(email);}
if(this._autoSubmitTags){tag.submit(this._tagCallbackFn);}else{tag.setLocalSave();this._tagCallbackFn(tag,{});}},_photoMouseMove:function(event){if(!this._getPhotoElement()){return this._destruct();}
if(this._taggingEnabled){return;}
if(!this.tagShowCallback&&!this.tagHideCallback){return;}
var photoTags=PhotoTag.tagsForPhoto(this.photoId,this.photoOwnerId);if(!photoTags){return;}
var mousePosition=Vector2.getEventPosition(event);var imagePosition=Vector2.getElementPosition(this._getPhotoElement());var imageDimensions=Vector2.getElementDimensions(this._getPhotoElement());var mouseRelPosition=mousePosition.sub(imagePosition);if(mouseRelPosition.x>0&&mouseRelPosition.x<imageDimensions.x&&mouseRelPosition.y>0&&mouseRelPosition.y<imageDimensions.y){var minDistance=imageDimensions.magnitude();var minTag=null;for(var i=0;i<photoTags.length;i++){var absolutePosition=photoTags[i].absoluteCenter(imageDimensions.x,imageDimensions.y);var vectorFromTag=absolutePosition.sub(mouseRelPosition);var tagDistance=vectorFromTag.magnitude();if(Math.abs(vectorFromTag.x)<=this.minTagDistance&&Math.abs(vectorFromTag.y)<=this.minTagDistance&&tagDistance<=minDistance){minDistance=tagDistance;minTag=photoTags[i];if(0==tagDistance){break;}}}}
if(!minTag&&this.showingTag&&this.tagHideCallback){this.showingTag=null;this.tagHideCallback(this.showingTag);}else if(minTag&&this.tagShowCallback&&minTag!=this.showingTag){this.showingTag=minTag;this.tagShowCallback(minTag);}},_isPhotoCropOn:function(){return window['photocrop']&&window['photocrop'].instance&&true;}});function PhotoTag(percentX,percentY,photoOwnerId,photoId){copy_properties(this,{centerPoint:new Vector2(percentX/100,percentY/100),photoOwnerId:photoOwnerId,photoId:photoId});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(photoId,photoOwnerId){return photoId+':'+photoOwnerId;},tagsForPhoto:function(photoId,photoOwnerId){var photoKey=PhotoTag._photoKey(photoId,photoOwnerId);return PhotoTag._tagList[photoKey]||[];},clearTagsForPhoto:function(photoId,photoOwnerId){var photoKey=PhotoTag._photoKey(photoId,photoOwnerId);PhotoTag._tagList[photoKey]=[];}});copy_properties(PhotoTag.prototype,{setTaggeeEmail:function(newEmail){if(this.saved){Util.log('You cannot edit the email of a saved tag');return this;}else{this.taggeeEmail=newEmail;}
return this;},setTaggeeName:function(newName){if(this.saved){Util.log('You cannot edit the name of a saved tag');return this;}else{this.taggeeName=newName;}
return this;},setTaggeeId:function(newId){if(this.saved){Util.log('You cannot edit the id of a saved tag');}else{this.taggeeId=newId;}
return this;},absoluteCenter:function(containerWidth,containerHeight){return this.centerPoint.mul(containerWidth,containerHeight);},submit:function(callback){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;}
callback=callback||bagofholding;var asyncData={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(asyncData).setHandler(bind(this,this._submitHandler,callback)).setErrorHandler(bind(this,this._submitHandler,callback)).setFinallyHandler(bind(this,function(){this._pendingAsync=false;})).send();},remove:function(callback,action){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 callback(this,{});}
callback=callback||bagofholding;var asyncData={pid:this.photoId,id:this.photoOwnerId,subject:this.taggeeId,name:this.taggeeName,action:action||'remove'};this._pendingAsync=true;new AsyncRequest().setURI(PhotoTag.SYNCING_ENDPOINT).setData(asyncData).setHandler(bind(this,this._removeHandler,callback)).setFinallyHandler(bind(this,function(){this._pendingAsync=false;})).send();return false;},invite:function(callback){var asyncData={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};callback=callback||bagofholding;var async=new AsyncRequest().setURI('/ajax/invite_photo_tag.php').setHandler(callback).setData(asyncData);var dialog=new Dialog().setAsync(async).show();return false;},_removeLocal:function(){var photoKey=PhotoTag._photoKey(this.photoId,this.photoOwnerId);var tags=PhotoTag._tagList[photoKey]||[];for(var i=0,len=tags.length;i<len;i++){if(tags[i]==this){tags.splice(i,1);break;}}},setLocalSave:function(){var photoKey=PhotoTag._photoKey(this.photoId,this.photoOwnerId);var list=PhotoTag._tagList[photoKey]=PhotoTag._tagList[photoKey]||[];PhotoTag._tagList[photoKey][list.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(callback,response){var error=response.getError();var payload=response.getPayload();if(error){ErrorDialog.showAsyncError(response);if(!payload['tag_success']){return;}}
this.setSaved();this.taggeeName=payload.taggeeName;this.taggeeId=payload.taggeeId;callback(this,payload);},_removeHandler:function(callback,response){this._removeLocal();(callback||bagofholding)(this,response.getPayload());}});

function exif_userpref_change(user_id,span_id){toggle(span_id);show=(ge(span_id).style.display=='none')?0:1;var post_vars={'user_id':user_id,'show':show}
new AsyncRequest().setURI('/ajax/photos_metadata.php').setData(post_vars).send();}

var PhotoPageTags={removeCallback:function(photoTag,payload){var tag_description=ge('phototags');if(tag_description&&undefined!==payload.tag_html){tag_description.setContent(HTML(payload.tag_html));}
PhotoTagController.getInstance('myphoto').hideTag();PhotoPageTags.resetInstructions();},addCallback:function(photoTag,payload){var tag_description=ge('phototags');if(tag_description&&undefined!==payload.tag_html){tag_description.setContent(HTML(payload.tag_html));}
var taggeeName=htmlize(photoTag.getText());var photoOwnerName=htmlize(payload.photoOwnerName);var successMessage='';if(payload.tag_success){successMessage='<b>';if(!payload.tags_need_approval){if(payload.user==photoTag.getTaggeeId()){successMessage+=_tx("Tag for yourself saved");}else{successMessage+=_tx("Tag for {name} saved",{'name':taggeeName});}}else{if(payload.user==photoTag.getTaggeeId()){successMessage+=_tx("Tag request for yourself sent to {photo-owner} for approval",{'photo-owner':photoOwnerName});}else{successMessage+=_tx("Tag request for {name} sent to {photo-owner} for approval",{'name':taggeeName,'photo-owner':photoOwnerName});}}
successMessage+='</b>.<br/>';}else{successMessage='<b style="color:red">'+_tx("There was an error tagging this photo. Try again later.")+'</b><br />';}
if(payload.invite_sent){successMessage+='<b style="color: green">'+_tx("An invitation and friend request have been sent to {name}",{name:taggeeName})+'</b><br/>';}
if(!payload.tags_need_approval){successMessage+=_tx("You can continue to tag the photo below.");}else{successMessage+=_tx("You can continue to request tags in the photo below.");}
successMessage+='<br/>'+_tx("When you are done, click the \"Done Tagging\" button to resume browsing.");hide('tagging_instructions_default_message');set_inner_html($('tagging_instructions_status_message'),successMessage);PhotoPageTags.focusInstructions();},showTaggingUI:function(){window['photocrop']&&window['photocrop'].destroy();PhotoTagController.getInstance('myphoto').enableTagging(PhotoPageTags.addCallback);show('tagging_instructions');PhotoPageTags.resetInstructions();PhotoPageTags.focusInstructions();},resetInstructions:function(){$('tagging_instructions_status_message').empty();show('tagging_instructions_default_message');},hideTaggingUI:function(){hide('tagging_instructions');PhotoTagController.getInstance('myphoto').disableTagging();},focusInstructions:function(){var tagging_pos=Vector2.getElementPosition($('tagging_instructions'));if(Vector2.getScrollPosition().y>tagging_pos.y){DOMScroll.scrollTo(tagging_pos.sub(0,8));}}};

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