/*
HTTP Host: b.static.ak.fbcdn.net
Generated: March 21st 2010 8:13:23 AM PDT
Machine: 10.16.140.101
Locale: nu_ll
Path: js/2w9ovm0wvxa8w4ow.pkg.js
*/

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


function Beep(owner,properties){copy_properties(this,properties);this.unread=true;this._owner=owner;this._node=$(HTML(this.html).getNodes()[0]);CSS.setOpacity(this._node,'0');this._node.find('a.beeper_x').listen('click',this.remove.bind(this));var elements=this._node.scry('a.undo_link');if(elements.length==1){elements[0].listen('click',this.onUndoClick.bind(this,elements[0]));}
this._node.listen('mouseover',this.onMouseOver.bind(this));this._node.listen('mouseout',this.onMouseOut.bind(this));}
copy_properties(Beep,{REMOVE_BEEP_ANIM_MS:250,UNDONE_BEEP_DELAY_MS:1000});copy_properties(Beep.prototype,{onMouseOver:function(event){this._node.addClass('UIBeep_Selected');this._selected=true;this.setEdges();},onMouseOut:function(event){this._node.removeClass('UIBeep_Selected');this._selected=false;this.setEdges();},onUndoClick:function(link){new AsyncRequest().setURI('/ajax/presence/undo_send.php').setData({alert_id:this.alertId}).setHandler(function(){DOM.replace(link,$N('span',{className:'undo_link'},_tx("Deshecho")));this.remove.bind(this).defer(Beep.UNDONE_BEEP_DELAY_MS);}.bind(this)).send();},xout:function(){this._owner.pause();var cancel_handler=function(){this._owner.unpause();}.bind(this);ChatNotifications.showReportDialog(this.applicationName,this.onHideBeepSpam.bind(this,false),this.onHideBeepSpam.bind(this,true),cancel_handler);},onHideBeepSpam:function(isSpamReport){ChatNotifications.markAppNotificationSpam(this.applicationId,this.platformType,isSpamReport);this._owner.hideBeepsByApplication(this.applicationId);presenceNotifications.hideNotifications(this.applicationId);this._owner.unpause(Beeper.DEFAULT_DELAY_MS);},remove:function(){animation(this._node).to('width',30).to('height',27).to('margin-left',169).to('opacity',0).duration(Beep.REMOVE_BEEP_ANIM_MS).ease(animation.ease.both).ondone(function(){this._node.remove();this._owner.beeps.remove(this);if(!this._owner.beeps.length){this._owner.reset();}else{this._owner.updateEdges();}}.bind(this)).go();this.fadeOut(Beep.REMOVE_BEEP_ANIM_MS);},markRead:function(){this.unread=false;},endFade:function(){if(this._node){this._node.removeClass('UIBeep_Fading');}
this._owner.setFading(false,this._isTop,this._isBottom);},fadeOut:function(duration){this._node.addClass('UIBeep_Fading');this._owner.setFading(true,this._isTop,this._isBottom);var thumb=this._node.scry('img.beeper_pic');if(thumb&&thumb.length){thumb=thumb[0];animation(thumb).to('width',20).to('height',20).duration(duration).blind().go();}
var icon=this._node.find('div.UIBeep_Icon');animation(icon).from('width',40).to(20).duration(duration).ondone(this.endFade.bind(this)).go();},fadeIn:function(duration){this._owner.fadeIn(this._isTop,this._isBottom,duration);animation(this._node).to('opacity',1.0).ease(animation.ease.both).duration(duration).show().go();},setEdges:function(){if(this._isTop){this.setTop(true);}
if(this._isBottom){this.setBottom(true);}},setBottom:function(value){this._isBottom=value;CSS.conditionClass(this._node,'UIBeep_Bottom',value);if(value){this._owner.setBottom(this._selected);}},setTop:function(value){this._isTop=value;CSS.conditionClass(this._node,'UIBeep_Top',value);if(value){this._owner.setTop(this._selected);}},getNode:function(){return this._node;}});

function Beeper(root){this._baseRoot=root;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(instance){Beeper._instance=instance;},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(Arbiter.BEEPS_EXPIRED);},onPresenceTabOpen:function(type,data){tab=data.tabID;if(tab&&tab=='presence_notifications_tab'){this.reset();}},mouseover:function(event){this.pause();this.markRead();},mouseout:function(event){this.unpause();},fromMessage:function(properties){if(!this._root){this.reset();}
var beep=new Beep(this,properties);this.addBeep(beep);},addBeep:function(beep){if(presence.focusedTab=='presence_notifications_tab'){return;}
if(this._animatingOut){this.addBeep.bind(this,beep).defer(500);return;}
this.beeps.push(beep);beep.setTop(true);if(this.beeps.length==1){beep.setBottom(true);this._root.addClass('UIBeeper_Active');}else{beep.setBottom(false);this.beeps[this.beeps.length-2].setTop(false);}
this._restartTimer(Beeper.DEFAULT_DELAY_MS);this._inside.prependContent(beep.getNode());beep.fadeIn(Beeper.FADE_IN_ANIMATION_MS);},hasIncoming:function(){for(var i=0;i<this.beeps.length;i++){if(this.beeps[i].type=='NotificationBeep'&&!this.beeps[i].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(0.3).to('opacity',0).to('height',0).ease(animation.ease.both).ondone(function(){this.reset();}.bind(this)).go();this._animatingOut=true;for(var ii=0;ii<this.beeps.length;ii++){this.beeps[ii].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(skipAsyncRequest,alertsRead){if(!alertsRead){alertsRead=[];this.beeps.each(function(beep){if(beep.unread&&beep.type=='NotificationBeep'&&!beep.outgoing){alertsRead.push(beep.alertId);}});}
var alertMap=Object.from(alertsRead);this.beeps.each(function(beep){if(alertMap[beep.alertId]){beep.markRead();}});if(!skipAsyncRequest&&alertsRead.length){presenceNotifications.notifyRead(alertsRead);}},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(extendMs){if(!extendMs){extendMs=Beeper.DEFAULT_UNPAUSE_MS;}
this._paused--;if(this._paused<=0){this._root.removeClass('UIBeeper_Paused');this._restartTimer(extendMs);}},_restartTimer:function(extraTime){if(this._timer){clearInterval(this._timer);}
this._timer=this.expireBeeps.bind(this).defer(extraTime);},updateEdges:function(){if(this.beeps.length<=0){return;}
this.beeps[0].setBottom(true);this.beeps[this.beeps.length-1].setTop(true);},hideBeepsByApplication:function(applicationId){for(var ii=0;ii<this.beeps.length;ii++){if(this.beeps[ii].applicationId==applicationId){this.beeps[ii].remove();}}},fadeIn:function(includeTop,includeBottom,duration){var toFade=[];if(includeTop){toFade.push(this._top);toFade.push(this._top_selected);}
if(includeBottom){toFade.push(this._bottom);toFade.push(this._bottom_selected);}
for(var i=0;i<toFade.length;i++){animation(toFade[i]).from('opacity',0).to('opacity',1).ease(animation.ease.both).duration(duration).go();}},setFading:function(isFading,includeTop,includeBottom){var toggler=(isFading?CSS.addClass:CSS.removeClass);if(includeTop){toggler(this._root,'UIBeeper_Fading_Top');}
if(includeBottom){toggler(this._root,'UIBeeper_Fading_Bottom');}},setTop:function(selected){CSS.conditionClass(this._top,'display_none',selected);CSS.conditionClass(this._top_selected,'display_none',!selected);},setBottom:function(selected){CSS.conditionClass(this._bottom,'display_none',selected);CSS.conditionClass(this._bottom_selected,'display_none',!selected);}});

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