/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  February 10th 2010 12:55:17 AM PST                           */
/*      Machine:  10.16.140.110                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/page/photostream.js h:3q9d88kb                            */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/page/photostream.js                                       */

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

function Photostream(img,_L1,_L2,_L3,uid,pid,pos,_L7,_L8,_L9,_La,_Lb){Photostream.instance=this;if(_L1)(new Image()).src=_L1;if(ua.safari()<500||ua.firefox()<2)return;copy_properties(this,{data:copy_properties(_L3,{async:true}),seq:0,pid:pid,img:img,minseq:0,isSearch:_L2});copy_properties(this,{error:0,album:new Array(_L7),has_moved:false,jumps:{},unseen:null,cursor:null,is_rendered:true,queue:new TaskQueue(),loads:[],pagesize:20,fetched:{},pending:(_La?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:_Lb});var _Lc=this.onnext.bind(this);var _Ld=this.onprev.bind(this);var _Le=this.onplay.bind(this);var _Lf=this.onstop.bind(this);(ge('photonav_next')||{}).onclick=_Lc;(ge('photonav_prev')||{}).onclick=_Ld;if(this.displayStartShow)this.displayStartShow.onclick=_Le;if(this.displayStopShow)this.displayStopShow.onclick=_Lf;this.img.onclick=chain(this.img.onclick,_Lc);this.img.onload=null;if(ua.ie()<7)this.img.galleryimg="no";KeyEventController.registerKey('RIGHT',_Lc);KeyEventController.registerKey('LEFT',_Ld);this.cursor=pos;this.requestPage(_L8);if(_L9)onunloadRegister(bind(this,function(type){scribe_log(type?'photostream':'photostream_ajax',this.seq);},_La!=undefined),true);PageTransitions.registerHandler(bind(this,'pageTransitionHandler'));this.orig_params=URI.getRequestURI().getQueryData();}copy_properties(Photostream.prototype,{debug:bagofholding,setupCaptions:function(uid,pid,_L2){var _L3=$('photocaption_parent');if(Photocaption){var _L4={typeaheadSource:_L2,successCallback:this.setDataFromCaption.bind(this),beginEditCallback:this.stopSlideshow.bind(this)};var _L5=this.album[this.cursor];var id=_L5?_L5.id:uid;var pid=_L5?_L5.pid:pid;this.caption=new Photocaption(_L3,id,pid,_L4);}},requestPage:function(_L0){if(this.fetched[_L0])return;this.fetched[_L0]=true;this.pending++;new AsyncRequest().setURI(this.isSearch?'/photo_search.php':'/album.php').setMethod('GET').setReadOnly(true).setData(copy_properties(this.data,{page:_L0})).setHandler(bind(this,'didGetAlbumResponse',_L0)).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 _L1=(this.cursor+1)%this.album.length;if(this.slideshowActive)clearTimeout(this.lastTimeout);this.checkAndRefreshAds();if(!this.hideKeyPress(e)&&this.showPhoto(_L1))return $E(e).kill();},hideKeyPress:function(e){if(window.Dialog&&window.Dialog.getCurrent()||this.caption&&this.caption.mentionsIsFocused()){event=$E(e);var _L1=event?Event.getKeyCode(event):-1;switch(_L1){case KEYS.RIGHT:case KEYS.LEFT:return true;}}return false;},setDataFromCaption:function(_L0){this.album[this.cursor].caption=_L0.rendered;this.album[this.cursor].caption_plaintext=_L0.plaintext;},slideshowTimeoutCallback:function(){var _L0=(this.cursor+1)%this.album.length;if(this.slideshowActive)if(this.album[_L0]){this.showPhoto(_L0);}else{this.requestPage(1+Math.floor(_L0/this.pagesize));this.slideshowGoNext(500);}},onprev:function(e){var _L1=((this.cursor-1)+this.album.length)%this.album.length;this.checkAndRefreshAds();if(!this.hideKeyPress(e)&&this.showPhoto(_L1))return $E(e).kill();},onplay:function(e){this.slideshowActive=true;if(!this.slideshowEventsInited){var _L1=this.onSlideshowInputEvent.bind(this);Event.listen(window,{keypress:_L1,mousedown:_L1});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 _L1=e.getTarget();var _L2=true;switch(_L1){case 'my_photo':case 'photonav_next':case 'photonav_prev':case 'photo_start_show':case 'photo_stop_show':_L2=false;break;default:break;}if(_L2){this.stopSlideshow();clearTimeout(this.lastTimeout);}return true;},slideshowGoNext:function(_L0){clearTimeout(this.lastTimeout);this.lastTimeout=setTimeout(this.slideshowTimeoutCallback.bind(this),_L0);},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(_L0){if(this.error)return false;if(this.caption&&this.caption.isUpdating())return true;var _L1=this.has_moved&&!this.album[this.cursor];this.has_moved=true;this.setCursor(_L0);var _L2=this.album[_L0];if(_L2){Arbiter.inform(PhotostreamConstants.ShowPhoto,{'node':{'href':URI.getRequestURI().toString()},'pid':_L2.pid,'aid':_L2.id,'ss':this.slideshowActive});goURI(URI.getRequestURI().addQueryData({pid:_L2.pid,id:_L2.id,fbid:_L2.fbid}).removeQueryData('alert'));}else{if(!_L1){this.showLoadIndicator();this.prepareToLeavePhoto();}this.requestPage(1+parseInt(_L0/this.pagesize));}return true;},prepareToLeavePhoto:function(){if(!this.readied){this.readied=true;var _L0=env_get('ps_rate')||(5);this.queue.setOption('concurrency',_L0).ready(_L0);}if(ge('changessaved'))DOM.remove(ge('changessaved'));if(ge('photocrop_error'))DOM.remove(ge('photocrop_error'));PhotoPageTags.resetInstructions();},setCursor:function(_L0){if(_L0===this.cursor)return;this.readPhotoState();this.is_rendered=false;this.cursor=_L0;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 _L0=this.album[this.cursor];var img=document.createElement('img');copy_properties(img.style,{display:'none'});if(!_L0.seen){var _L2=(parseInt(this.cursor/this.pagesize)+1)*this.pagesize;_L2=Math.min(_L2,this.album.length);var _L3=((_L2-this.cursor)<=3);_L0.seen=true;--this.unseen;if(_L3&&!this.pending){var _L4=parseInt(this.cursor/this.pagesize)+1;var _L5=parseInt((this.album.length-1)/this.pagesize)+1;var _L6=null;for(ii=_L4+1;ii<=_L5;ii++)if(!this.fetched[ii]){_L6=ii;break;}if(_L6===null)for(ii=1;ii<_L4;ii++)if(!this.fetched[ii]){_L6=ii;break;}if(_L6!==null)this.requestPage(_L6);}}if(!this.photoLoadTimeout)this.photoLoadTimeout=setTimeout(this.showLoadIndicator.bind(this),750);img.seq=++this.seq;img.onload=bind(this,'renderPhoto',img,_L0);img.src=_L0.src;},renderPhoto:function(img,_L1){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(_L1.caption));this.displayPhototags&&set_inner_html(this.displayPhototags,_L1.tags);this.displayComments&&set_inner_html(this.displayComments,_L1.comments);this.displayBadge&&set_inner_html(this.displayBadge,_L1.badge);this.displayActions&&set_inner_html(this.displayActions,_L1.actions);this.displayContext&&set_inner_html(this.displayContext,_L1.context_info);this.displayPublicLink&&set_inner_html(this.displayPublicLink,_L1.public_link);if(this.caption)this.caption.setCaptionData(_L1.id,_L1.pid,_L1.caption_plaintext);this.is_rendered=true;if(this.displayShare)this.displayShare.href='/ajax/share_dialog.php?'+_L1.share;if(window.PhotoTagController&&PhotoTagController.getInstance('myphoto')){PhotoTagController.getInstance('myphoto').setPhotoData(_L1.id,_L1.pid);}else PhotoTagViewer.getInstance('myphoto').setPhotoData(_L1.id,_L1.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(_L0,_L1){this.pending--;var _L2=_L1.getPayload();var _L3=(this.has_moved&&this.cursor!==null&&!this.album[this.cursor]);var img,_L5,_L6,pos,_L8=_L2.data;for(var ii=0;ii<_L8.length;++ii){data=_L8[ii];pos=(this.pagesize*(_L0-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.fbid]=pos;img=new Image();_L6=bind(img,function(src){this.src=src;},data.src);_L5=new Task(_L6);img.onload=_L5.didComplete.bind(_L5);this.queue.addTask(_L5);}this.unseen+=_L8.length;if(_L2.album_count){this.album.length=_L2.album_count;this.updateCountText();}if(_L3)this.showPhoto(this.cursor);},didGetAlbumError:function(_L0){Util.error(_L0.getErrorDescription());this.error=_L0.getError();ErrorDialog.showAsyncError(_L0);},pageTransitionHandler:function(uri){var _L1=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]!=_L1[v])return false;if(_L1.alert!==undefined)return false;fbid=parseInt(_L1.fbid,10);if(this.jumps[fbid]!==undefined){this.setCursor(this.jumps[fbid]);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_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(_L0){function _L1(){var _L2=new AsyncRequest().setURI('/ajax/profile/picture/remove.php').setData({remove:true,id:_L0}).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(_L1).show();return false;}

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