/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  January 12th 2010 9:39:59 AM PST                             */
/*      Machine:  10.16.140.108                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/presence/beeper.js h:9xtrgu07                             */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/presence/beeper.js                                        */

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

function Beeper(a){this._baseRoot=a;this._receiver=new LiveMessageReceiver(Beeper.BEEP_EVENT).setAppId(Beeper.APP_ID).setHandler(this.fromMessage.bind(this)).register();Arbiter.subscribe(PresenceMessage.TAB_OPENED,this.onPresenceTabOpen.bind(this));}copy_properties(Beeper,{BEEP_EVENT:'beep_event',APP_ID:30729425562,CONTENT_ID:'BeeperBox',DEFAULT_DELAY_MS:10000,DEFAULT_UNPAUSE_MS:500,SLIDE_DOWN_ANIMATION_MS:700,FADE_IN_ANIMATION_MS:500,FADE_OUT_ANIMATION_MS:1250,_instance:null,setInstance:function(a){Beeper._instance=a;},getInstance:function(){Beeper.ensureInitialized();return Beeper._instance;},ensureInitialized:function(){if(!Beeper._instance)Beeper.setInstance(new Beeper($(Beeper.CONTENT_ID)));}});copy_properties(Beeper.prototype,{beeps:[],reset:function(){this.beeps=[];if(this._root)this._root.remove();this._root=$(this._baseRoot.cloneNode(true));this._root.listen('mouseover',this.mouseover.bind(this));this._root.listen('mouseout',this.mouseout.bind(this));DOM.insertAfter(this._baseRoot,this._root);this._full=this._root.find('div.UIBeeper_Full');this._inside=this._root.find('div.Beeps');this._top=this._root.find('img.UIBeeper_Top');this._top_selected=this._root.find('img.UIBeeper_Top_Selected');this._bottom=this._root.find('img.UIBeeper_Bottom');this._bottom_selected=this._root.find('img.UIBeeper_Bottom_Selected');if(this._timer)clearInterval(this._timer);this._timer=null;this._animation=null;this._animatingOut=false;this._paused=0;Arbiter.inform(ChatNotifications.BEEPS_EXPIRED);},onPresenceTabOpen:function(b,a){tab=a.tabID;if(tab&&tab=='presence_notifications_tab')this.reset();},mouseover:function(event){this.pause();this.markRead();},mouseout:function(event){this.unpause();},fromMessage:function(b){if(!this._root)this.reset();var a=new Beep(this,b);this.addBeep(a);},addBeep:function(a){if(presence.focusedTab=='presence_notifications_tab')return;if(this._animatingOut){this.addBeep.bind(this,a).defer(500);return;}this.beeps.push(a);a.setTop(true);if(this.beeps.length==1){a.setBottom(true);this._root.addClass('UIBeeper_Active');}else{a.setBottom(false);this.beeps[this.beeps.length-2].setTop(false);}this._restartTimer(Beeper.DEFAULT_DELAY_MS);this._inside.prependContent(a.getNode());a.fadeIn(Beeper.FADE_IN_ANIMATION_MS);},hasIncoming:function(){for(var a=0;a<this.beeps.length;a++)if(this.beeps[a].type=='NotificationBeep'&&!this.beeps[a].outgoing)return true;return false;},expireBeeps:function(){if(this.beeps.length<=0)return;this.fadeOut();},shrinkOut:function(){animation(this._full).to('width',30).to('height',27*this.beeps.length).to('margin-left',169).to('margin-bottom',5).duration(Beeper.SLIDE_DOWN_ANIMATION_MS).ease(animation.ease.both).checkpoint(.3).to('opacity',0).to('height',0).ease(animation.ease.both).ondone(function(){this.reset();}.bind(this)).go();this._animatingOut=true;for(var a=0;a<this.beeps.length;a++)this.beeps[a].fadeOut(Beeper.SLIDE_DOWN_ANIMATION_MS);},fadeOut:function(){this._animation=animation(this._full).duration(Beeper.FADE_OUT_ANIMATION_MS).to('opacity',0).blind().ease(animation.ease.begin).ondone(function(){this.reset();}.bind(this));this._animation.undo=function(){this._animation.stop();CSS.setOpacity(this._full,1);}.bind(this);this._animation.go();},markRead:function(c,b){if(!b){b=[];this.beeps.each(function(d){if(d.unread&&d.type=='NotificationBeep'&&!d.outgoing)b.push(d.alertId);});}var a=Object.from(b);this.beeps.each(function(d){if(a[d.alertId])d.markRead();});if(!c&&b.length)presenceNotifications.notifyRead(b);},pause:function(){if(this._animatingOut)return;if(this._animation&&this._animation.undo){this._animation.undo();this._animation=null;return;}this._pauseTimer();this._root.addClass('UIBeeper_Paused');this._paused++;},_pauseTimer:function(){if(this._timer)clearInterval(this._timer);},unpause:function(a){if(!a)a=Beeper.DEFAULT_UNPAUSE_MS;this._paused--;if(this._paused<=0){this._root.removeClass('UIBeeper_Paused');this._restartTimer(a);}},_restartTimer:function(a){if(this._timer)clearInterval(this._timer);this._timer=this.expireBeeps.bind(this).defer(a);},updateEdges:function(){if(this.beeps.length<=0)return;this.beeps[0].setBottom(true);this.beeps[this.beeps.length-1].setTop(true);},hideBeepsByApplication:function(a){for(var b=0;b<this.beeps.length;b++)if(this.beeps[b].applicationId==a)this.beeps[b].remove();},fadeIn:function(d,c,a){var e=[];if(d){e.push(this._top);e.push(this._top_selected);}if(c){e.push(this._bottom);e.push(this._bottom_selected);}for(var b=0;b<e.length;b++)animation(e[b]).from('opacity',0).to('opacity',1).ease(animation.ease.both).duration(a).go();},setFading:function(c,b,a){var d=(c?CSS.addClass:CSS.removeClass);if(b)d(this._root,'UIBeeper_Fading_Top');if(a)d(this._root,'UIBeeper_Fading_Bottom');},setTop:function(a){CSS.conditionClass(this._top,'display_none',a);CSS.conditionClass(this._top_selected,'display_none',!a);},setBottom:function(a){CSS.conditionClass(this._bottom,'display_none',a);CSS.conditionClass(this._bottom_selected,'display_none',!a);}});

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