/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  March 8th 2010 8:07:45 AM PST                                */
/*      Machine:  10.16.140.107                                                */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/71jaqcq7jw0s08gg.pkg.js                                   */

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

var ChatUserInfos={};
function ChatTabActions(a){this._container=a;this._actions={};this._actionOrder=[];this._visibilityChanged=false;this._anyVisible=false;this.actionClass='action';}copy_properties(ChatTabActions.prototype,{anyVisible:function(){return this._anyVisible;},appendAction:function(c,b,a){this._addAction(c,b,a);this._actionOrder.push(c);return this;},prependAction:function(c,b,a){this._addAction(c,b,a);this._actionOrder.unshift(c);return this;},setVisible:function(b,c){var a=this._actions[b];if(a.visible!=c){a.visible=c;this._visibilityChanged=true;}return this;},refresh:function(){if(this._visibilityChanged){this._render();this._visibilityChanged=false;return true;}return false;},_render:function(){DOM.empty(this._container);var c=this._actions;var b=this._actionOrder;this._anyVisible=false;var d=[];for(var e=0;e<b.length;++e){var a=c[b[e]];if(a.visible){if(this._anyVisible)d.push($N('span',{className:'divider'},'|'));d.push(a.create_element());this._anyVisible=true;}}DOM.appendContent(this._container,d);this._container.style.display=this._anyVisible?'block':'none';},_addAction:function(c,b,a){if(typeof b=='string'){var d=b;b=function(){return $N('span',{className:this.actionClass},d);}.bind(this);}this._actions[c]={create_element:function(){var e=b();Event.listen(e,'click',a);return e;},visible:false};this._visibilityChanged=true;}});
if(typeof deconcept=="undefined")var deconcept={};if(typeof deconcept.util=="undefined")deconcept.util={};if(typeof deconcept.SWFObjectUtil=="undefined")deconcept.SWFObjectUtil={};deconcept.SWFObject=function(h,d,j,c,i,a,f,l,g,b){if(!document.getElementById)return;this.DETECT_KEY=b?b:'detectflash';this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params={};this.variables={};this.attributes=[];this.fallback_html='';this.fallback_js_fcn=function(){};if(h)this.setAttribute('swf',h);if(d)this.setAttribute('id',d);if(j)this.setAttribute('width',j);if(c)this.setAttribute('height',c);this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(i){if(!(i instanceof Array))i=[i];var k;i.each(function(n){k=new deconcept.PlayerVersion(n.toString().split('.'));if(k.major==this.installedVer.major){this.setAttribute('version',k);return;}else if(!this.getAttribute('version')||k.major<this.getAttribute('version').major)this.setAttribute('version',k);}.bind(this));}if(!window.opera&&document.all&&this.installedVer.major>7)if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}if(a)this.addParam('bgcolor',a);var e=f?f:'high';this.addParam('quality',e);this.setAttribute('useExpressInstall',false);this.setAttribute('doExpressInstall',false);var m=(l)?l:window.location;this.setAttribute('xiRedirectUrl',m);this.setAttribute('redirectUrl','');if(g)this.setAttribute('redirectUrl',g);};deconcept.SWFObject.prototype={useExpressInstall:function(a){this.xiSWFPath=!a?"/swf/expressinstall.swf":a;this.setAttribute('useExpressInstall',true);},setAttribute:function(a,b){this.attributes[a]=b;},getAttribute:function(a){return this.attributes[a]||"";},addParam:function(a,b){this.params[a]=b;},getParams:function(){return this.params;},addVariable:function(a,b){this.variables[a]=b;},getVariable:function(a){return this.variables[a]||"";},getVariables:function(){return this.variables;},getVariablePairs:function(){var b=[];var a;var c=this.getVariables();for(a in c)b[b.length]=a+"="+c[a];return b;},getSWFHTML:function(){var d="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute('swf',this.xiSWFPath);}d='<embed type="application/x-shockwave-flash" src="'+htmlspecialchars(this.getAttribute('swf'))+'" width="'+htmlspecialchars(this.getAttribute('width'))+'" height="'+htmlspecialchars(this.getAttribute('height'))+'" style="'+htmlspecialchars(this.getAttribute('style')||"")+'"';d+=' id="'+htmlspecialchars(this.getAttribute('id'))+'" name="'+htmlspecialchars(this.getAttribute('id'))+'" ';var c=this.getParams();for(var a in c)d+=htmlspecialchars(a)+'="'+htmlspecialchars(c[a])+'" ';var b=this.getVariablePairs().join("&");if(b.length>0)d+='flashvars="'+b+'"';d+='/>';}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute('swf',this.xiSWFPath);}d='<object id="'+this.getAttribute('id')+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+this.getAttribute('width')+'" height="'+this.getAttribute('height')+'" style="'+(this.getAttribute('style')||"")+'">';d+='<param name="movie" value="'+this.getAttribute('swf')+'" />';var c=this.getParams();for(var a in c)d+='<param name="'+a+'" value="'+c[a]+'" />';var b=this.getVariablePairs().join("&");if(b.length>0)d+='<param name="flashvars" value="'+b+'" />';d+="</object>";}return d;},write:function(a){if(this.getAttribute('useExpressInstall')){var b=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(b)&&!this.installedVer.versionIsValid(this.getAttribute('version'))){this.setAttribute('doExpressInstall',true);this.addVariable("MMredirectURL",escape(this.getAttribute('xiRedirectUrl')));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}var c=(typeof a=='string')?document.getElementById(a):a;if(this.skipDetect||this.getAttribute('doExpressInstall')||this.installedVer.versionIsValid(this.getAttribute('version'))){c.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute('redirectUrl')!="")document.location.replace(this.getAttribute('redirectUrl'));need_version=this.getAttribute('version').major+'.'+this.getAttribute('version').minor+'.'+this.getAttribute('version').rev;have_version=this.installedVer.major+'.'+this.installedVer.minor+'.'+this.installedVer.rev;this.fallback_js_fcn(have_version,need_version);c.innerHTML=this.fallback_html;}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var a=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){for(k=0;k<navigator.plugins.length;k++)try{x=navigator.plugins[k];if(x.name=='Shockwave Flash'){PlayerVersion_tmp=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));if(typeof a=='undefined'||PlayerVersion_tmp.major>a.major||(PlayerVersion_tmp.major==a.major&&(PlayerVersion_tmp.minor>a.minor||(PlayerVersion_tmp.minor==a.minor&&PlayerVersion_tmp.rev>a.rev))))a=PlayerVersion_tmp;}}catch(honk){}}else if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var b=1;var c=3;while(b)try{c++;b=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+c);a=new deconcept.PlayerVersion([c,0,0]);}catch(e){b=null;}}else{try{var b=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var b=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");a=new deconcept.PlayerVersion([6,0,21]);b.AllowScriptAccess="always";}catch(e){if(a.major==6)return a;}try{b=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(b!=null)a=new deconcept.PlayerVersion(b.GetVariable("$version").split(" ")[1].split(","));}return a;};deconcept.PlayerVersion=function(a){this.major=a[0]!=null?parseInt(a[0]):0;this.minor=a[1]!=null?parseInt(a[1]):0;this.rev=a[2]!=null?parseInt(a[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(a){if(this.major<a.major)return false;if(this.major>a.major)return true;if(this.minor<a.minor)return false;if(this.minor>a.minor)return true;if(this.rev<a.rev)return false;return true;};deconcept.util={getRequestParameter:function(c){var d=document.location.search||document.location.hash;if(c==null)return d;if(d){var b=d.substring(1).split("&");for(var a=0;a<b.length;a++)if(b[a].substring(0,b[a].indexOf("="))==c)return b[a].substring((b[a].indexOf("=")+1));}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var b=document.getElementsByTagName("OBJECT");for(var a=b.length-1;a>=0;a--){b[a].style.display='none';for(var c in b[a])if(typeof b[a][c]=='function')b[a][c]=function(){};}};if(!document.getElementById&&document.all)document.getElementById=function(a){return document.all[a];};var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;var flash_update_dialog_shown=false;function spawn_flash_update_dialog(a,b){if(flash_update_dialog_shown)return;flash_update_dialog_shown=true;new AsyncRequest().setURI('/ajax/flash_update_dialog.php').setData({have_version:a,need_version:b}).setMethod('GET').setReadOnly(true).send();}function setFlashFallback(d,g){var b=ge(d);var a=deconcept.SWFObjectUtil.getPlayerVersion();var e;g.each(function(h){h=new deconcept.PlayerVersion(h.toString().split('.'));if(h.major==a.major){e=h;return;}else if(typeof e=='undefined'||h.major<e.major)e=h;}.bind(this));if(b&&a.major>0){var c=a.major+'.'+a.minor+'.'+a.rev;var f=e.major+'.'+e.minor+'.'+e.rev;b.innerHTML=_tx("Flash {required-version} is required to view this content. Your current version is {current-version}. Please download the latest Flash Player.",{'required-version':f,'current-version':c});}}function getFlashPlayer(){goURI('http://get.adobe.com/flashplayer');return false;}
var Sound=(function(){var a=false;var b='so_sound_player';return {init:function(){if(a)return;a=true;var c=document.createElement('div');c.id='sound_player_holder';document.body.appendChild(c);try{var d=new SWFObject('/swf/SoundPlayerHater.swf',b,'1px','1px',['9.0.159.0','10.0.22.87'],'#ffffff');d.addParam('allowscriptaccess','always');d.addParam('wmode','transparent');d.addVariable('swf_id',b);d.fallback_html=' ';d.write(c.id);window[b]=d;}catch(swfex){}},play:function(d,f){Sound.init();var g=URI(d);if(!g.getDomain())d=URI(env_get('static_base')).setPath(g.getPath()).toString();var e=document[b]||window[b];var c;if(/\.mp3$/.test(d))if(e){if(!e.playSound&&e.length)e=e[0];if(e.playSound){e.playSound(d,!!f);return;}}c=ge('sound');if(!c){c=document.createElement('span');c.setAttribute('id','sound');DOM.getRootElement().appendChild(c);}c.innerHTML='<embed src="'+d+'" autostart="true" loop="false" '+'hidden="true" />';}};})();
function html_wordwrap(i,l,k){if(typeof l=='undefined')l=60;if(typeof k!='function')k=htmlize;var f=new RegExp("\\S{"+(l+1)+"}",'g');var h=0;var j=i;var g=[];var e=i.match(f);if(e)for(var b=0;b<e.length;b++){var c=e[b];var d=h+j.indexOf(c);var a=i.substring(h,d);if(a)g.push(k(a));g.push(k(c)+'<wbr/>');h=d+c.length;j=i.substring(h);}if(j)g.push(k(j));return g.join('');}function text_get_hyperlinks(k){if(typeof(k)!='string')return [];var f=k.match(/(?:(?:ht|f)tps?):\/\/[^\s"',]*[^\s"'.,?!]/ig);if(f&&f.length){var a={'>':'<',')':'(',']':'['};var c,d,g=0,e,h,j,i;for(var b=0;b<f.length;b++){d=f[b];c=a[d[d.length-1]];if(c){e=k.indexOf(d);h=k.substr(g,e);if(h.indexOf(c)!=-1)f[b]=d.substr(0,d.length-1);g=e+d.length;}prev_link=d;}}return f;}function html_hyperlink(q,u,v,n){var a={'<':'>','*':'*','{':'}','[':']',"'":"'",'"':'"','#':'#','+':'+','-':'-','(':')'};if(typeof(q)=='undefined'||!q.toString)return '';if(typeof u!='function')u=htmlize;if(typeof v!='function')v=htmlize;var q=q.toString();var f=text_get_hyperlinks(q);var p=0;var s=q;var o=[];var s=q;if(f){var l=n?ge('post_form_id'):null;var m=l?l.value:'';for(var j=0;j<f.length;j++){var h=f[j];var e=p+s.indexOf(h);var r=h.length;var k=q.substring(p,e);if(k)o.push(u(k));var t='';if(e>0){var b=q[e-1];if(typeof a[b]!='undefined'){var c=a[b];var d=h.indexOf(c);if(d!=-1){t=u(h.substring(d));h=h.substring(0,d);}}}var g=v(h);if(n){var i="http://www.facebook.com/l.php?u="+URI.encodeComponent(h)+'&h='+m;}else var i=h.replace(/"/g,'%22');o.push('<a href="'+i+'" target="_blank" rel="nofollow">'+g+'</a>'+t);p=e+r;s=q.substring(p);}}if(s)o.push(u(s));return o.join('');}function nl2br(a){if(typeof(a)=='undefined'||!a.toString)return '';return a.toString().replace(/\n/g,'<br />');}function is_email(a){return /^([\w!.%+\-])+@([\w\-])+(?:\.[\w\-]+)+$/.test(a);}
var Emote={_initialized:false,_imageBase:null,_emoteMap:null,_emoteOrderMap:null,_imageURLs:null,_regex:null,_mapOverlay:null,initImageURL:function(a){Emote._imageURL=a;},initExtraEmoticons:function(a){Emote._mapOverlay=a;},_init:function(){var f=env_get('static_base');Emote._imageBase=f+'images/emote/';Emote._blankImgSrc=f+'images/blank.gif';var a=['smile','frown','tongue','grin','gasp','wink','glasses','sunglasses','grumpy','unsure','cry','devil','angel','kiss','heart','kiki','squint','confused','upset','pacman','colonthree'];Emote._emoteMap={':-)':['\\:\\-\\)','smile'],':)':['\\:\\)','smile'],':]':['\\:\\]','smile'],'=)':['=\\)','smile'],':-(':['\\:\\-\\(','frown'],':(':['\\:\\(','frown'],':[':['\\:\\[','frown'],'=(':['=\\(','frown'],':-P':['\\:\\-P','tongue'],':P':['\\:P','tongue'],':-p':['\\:\\-p','tongue'],':p':['\\:p','tongue'],'=P':['=P','tongue'],':-D':['\\:\\-D','grin'],':D':['\\:D','grin'],'=D':['=D','grin'],':-O':['\\:\\-O','gasp'],':O':['\\:O','gasp'],':-o':['\\:\\-o','gasp'],':o':['\\:o','gasp'],';-)':['\\;\\-\\)','wink'],';)':['\\;\\)','wink'],'8-)':['8\\-\\)','glasses'],'8)':['8\\)','glasses'],'B-)':['B\\-\\)','glasses'],'B)':['B\\)','glasses'],'8-|':['8\\-\\|','sunglasses'],'8|':['8\\|','sunglasses'],'B-|':['B\\-\\|','sunglasses'],'B|':['B\\|','sunglasses'],'>:(':['>\\:\\(','grumpy'],'>:-(':['>\\:\\-\\(','grumpy'],':/':['\\:/','unsure'],':-/':['\\:\\-/','unsure'],':\\':['\\:\\\\','unsure'],':-\\':['\\:\\-\\\\','unsure'],":'(":["\\:'\\(",'cry'],'3:)':['3\\:\\)','devil'],'3:-)':['3\\:\\-\\)','devil'],'O:)':['O\\:\\)','angel'],'O:-)':['O\\:\\-\\)','angel'],':-*':['\\:\\-\\*','kiss'],':*':['\\:\\*','kiss'],'<3':['<3','heart'],'^_^':['\\^_\\^','kiki'],'-_-':['\\-_\\-','squint'],'o.O':['o\\.O','confused'],'O.o':['O\\.o','confused'],'>:O':['>\\:O','upset'],'>:-O':['>\\:\\-O','upset'],'>:o':['>\\:o','upset'],'>:-o':['>\\:\\-o','upset'],':v':['\\:v','pacman'],':|]':['\\:\\|\\]','robot'],':3':['\\:3','colonthree'],'<(")':['<\\(\\"\\)','penguin'],':putnam:':['\\:putnam\\:','putnam'],'(^^^)':['\\(\\^\\^\\^\\)','shark']};if(Emote._mapOverlay)copy_properties(Emote._emoteMap,Emote._mapOverlay);var d=[];for(var c in Emote._emoteMap)d.push(Emote._emoteMap[c][0]);var e='(?:^|\\s|\'|"|\\.)('+d.join('|')+')(?:\\s|\'|"|\\.|,|!|\\?|<br>|$)';Emote._regex=new RegExp(e);Emote._emoteOrderMap={};for(var b=0;b<a.length;b++)Emote._emoteOrderMap[a[b]]=b;Emote._initialized=true;},htmlEmote:function(j,l){if(typeof l!='function')l=htmlize;if(!Emote._initialized)Emote._init();var i=0;var k=j;var h=[];while(true){var e=Emote._regex.exec(k);if(!e||!e.length)break;var b=e[1];var d=Emote._emoteMap[b][1];var c=k.indexOf(b);var a=k.substring(0,c);if(a)h.push(l(a));h.push('<span class="emote_text">');h.push(b);h.push('</span><img class="emote_img" ');var f;if(typeof(f=Emote._emoteOrderMap[d])=='undefined'){h.push('src="');h.push(Emote._imageBase);h.push(d);h.push('.gif" ');}else{var g=((f*-16)-590);h.push('src="');h.push(Emote._blankImgSrc);h.push('" style="background:url(');h.push(Emote._imageURL);h.push(') ');h.push(g);h.push('px -84px no-repeat" ');}h.push('alt="');h.push(b);h.push('" />');k=k.substring(c+b.length);}if(k)h.push(l(k));return h.join('');}};
function ChatTab(a,c,e,b,f,d){this.chatDisplay=a;this.id=c;this.name=e;this.messageTypes={msg:{visible:true,user:true,preserveHistory:false},online:{visible:true,user:false,preserveHistory:true}};this.arbiter=new Arbiter();Arbiter.inform(ChatTab.GLOBALMESSAGETYPE.NEWTAB,{tab:this});this.tabRef='chatDisplay.tabs['+this.id+']';this.firstName=b;this.tabDisabled=false;this.numMissed=f;this.missedTime=d;this.focused=false;this.lastLogItem=null;this.historyLoaded=false;this.pendingSentMsgs=[];this.failedSentMsgs=[];this.sendingDisplayMsgID=null;this.historyRequestID=0;this.bounceAnimation=null;this.convTextProcessor=this._processConvText.bind(this);this.convTextEmoteProcessor=this._processConvTextEmote.bind(this);this.minTextHeight=presence.inPopoutWindow?this.minTextHeightPopout:this.minTextHeightPopin;this.typingState=this.INACTIVE;this.typingRemoteState=this.INACTIVE;this.typingLastKeystrokeAt=null;this.typingNotifyTimer=null;this.typingCheckTimer=null;this.lastMessageAt=null;this.lastMessageHadOfflineResponse=false;this._buildUI();this.addPopoutChat(c);this.loadData();this.handleVisibility(true);Sound.init();if(presence.inVideoChat)this.videochat_swf=ge(CallCenter.call(this.id)._callSWFID());}ChatTab.GLOBALMESSAGETYPE={NEWTAB:'chattabs/newtab'};ChatTab.TABMESSAGETYPE={HISTORYBEGIN:'chattabs/historybegin',HISTORYITER:'chattabs/historyiter',HISTORYEND:'chattabs/historyend',CREATETAB:'chattabs/createtab',RECEIVEMSG:'chattabs/receivemsg',DISPLAYCHAT:'chattabs/displaychat',USERINFOUPDATED:'chattabs/userinfoupdated'};copy_properties(ChatTab.prototype,{pendingToLogCompareWindow:60000,sendingCheckDelay:55000,sendingDisplayDelay:4000,convWrapLimit:30,handleWidth:136,popinWidth:226,popinHeight:250,popoutWidthOffset:180,flPopoutWidthOffset:200,minTextHeightPopin:13,minTextHeightPopout:32,maxTextHeight:77,msgBunchTime:60000,maxHandleLen:16,maxTitleLen:20,bounceDuration:50,bounceOrgPosition:-3,typingNotifyDelay:1000,typingKeystrokeExpiry:7000,INACTIVE:0,TYPING:1,isTabVisible:function(){return this.focused&&(presence.inPopoutWindow||!presence.poppedOut)&&(this.chatInfo.clientWidth>20||presence.inPopoutWindow);},start:function(){this._popSendQueue();},restart:function(){this.getHistory(true);this.handleResize.bind(this).defer();},loadData:function(){if(ChatUserInfos[this.id]){this.updateUserInfo();this.arbiter.inform(ChatTab.TABMESSAGETYPE.USERINFOUPDATED,{userInfo:ChatUserInfos[this.id]});}else this.chatDisplay.loadInitialUserInfo(this.id,this.name,this.firstName);if(this.chatDisplay.histories[this.id])this._setHistory(this.chatDisplay.histories[this.id]);},_onHistoryInitialHandler:function(a,b){if(a!=this.historyRequestID){presence.debug("tabs: got old history async, ignoring");return false;}},_onHistoryResponse:function(a,l){var b=l.getPayload();var n=b.userInfo;var h=b.history;ChatUserInfos[this.id]=n;buddyList.updateItemDisplay(this.id);this.updateUserInfo();this.arbiter.inform(ChatTab.TABMESSAGETYPE.USERINFOUPDATED,{userInfo:n});if(b.fls)buddyList.setFlids(this.id,b.fls);if(b.overlay)buddyList.addOverlayInfo(b.overlay);if(!h){this._showHistoryError();return;}var k=false;if(this.pendingSentMsgs.length>0&&h.length>0){var j=this.pendingSentMsgs[0];for(var c=h.length-1;c>=0;c--){var g=h[c];if(g.to==this.id){var m=Math.abs(j.time-g.time);if(m<this.pendingToLogCompareWindow&&j.text==g.msg.text){this._setMsgInfoMarkup(j.msgID,'');this.pendingSentMsgs.shift();this._popSendQueue();this.poppedSendQueue=true;break;}}}var e=h[h.length-1].time;for(var c=0;c<this.pendingSentMsgs.length;c++){var j=this.pendingSentMsgs[c];if(j.time<e)j.time=(++e);}}var i=this.chatDisplay.histories[this.id];if(i)if(h.length>0){var d=h[h.length-1];var f=d.time;for(var c=0;c<i.length;c++){var g=i[c];if(g.time>f)h.push(g);}}else h=i;this._setHistory(h);this.chatDisplay.histories[this.id]=h;if(a)if(!k)this._popSendQueue();},_onHistoryError:function(a){this._showHistoryError();},_showHistoryError:function(){show(this.chatHistoryError);this.scrollToBottom();},getHistory:function(a){var b=++(this.historyRequestID);new AsyncRequest().setInitialHandler(this._onHistoryInitialHandler.bind(this,b)).setHandler(this._onHistoryResponse.bind(this,a)).setErrorHandler(this._onHistoryError.bind(this)).setTransportErrorHandler(this._onHistoryError.bind(this)).setMethod('GET').setReadOnly(true).setOption('suppressErrorAlerts',true).setData({id:this.id}).setURI('/ajax/chat/history.php').send();},_setHistory:function(d){this.lastLogItem=null;var e='';var g=0;var i=[];Array.prototype.push.apply(i,this.failedSentMsgs);Array.prototype.push.apply(i,this.pendingSentMsgs);var f=0;var a=false;this.arbiter.inform(ChatTab.TABMESSAGETYPE.HISTORYBEGIN);for(var b=0;b<d.length;b++){var c=d[b];if(typeof this.messageTypes[c.type]==undefined)continue;if(!this.messageTypes[c.type].preserveHistory)a=true;for(;g<i.length;g++){var h=i[g];if(!this.messageTypes[h.type].preserveHistory)a=true;if(h.time>f&&h.time<=c.time){if(this.messageTypes[h.type].visible)e+=this._renderMsg(presence.user,this.id,h.time,h,h.msgID,h.isError,h.infoMarkup);}else break;}if(c.type=='msg'){e+=this._renderMsg(c.from,c.to,c.time,c.msg);}else if(c.type=='online'){e+=this._renderVisibilityChange(c.time,c.text);}else this.arbiter.inform(ChatTab.TABMESSAGETYPE.HISTORYITER,{item:c});this.lastLogItem=c;f=c.time;}this.arbiter.inform(ChatTab.TABMESSAGETYPE.HISTORYEND);for(;g<i.length;g++){var h=i[g];if(this.messageTypes[h.type].visible){e+=this._renderMsg(presence.user,this.id,h.time,h,h.msgID,h.isError,h.infoMarkup);this.lastLogItem={type:h.type,from:presence.user,to:this.id,time:h.time,msg:h};}}hide(this.chatHistoryError);this.chatConvContent.innerHTML=e;this.scrollToBottom();if(this.actions.setVisible('clearHistory',a).refresh())this.handleResize();this.historyLoaded=true;},_onClearHistoryError:function(b){var a=_tx("Chat");presence.showAsyncError(b,_tx("Couldn't clear {Chat} history",{Chat:a}));CSS.removeClass(this.tabHandle,'history_clearing');},_onClearHistoryResponse:function(d){CSS.removeClass(this.tabHandle,'history_clearing');var c=[];for(var a=0;a<this.chatDisplay.histories[this.id].length;a++){var b=this.chatDisplay.histories[this.id][a];if(typeof this.messageTypes[b.type]=='undefined'||this.messageTypes[b.type].preserveHistory)c.push(b);}this._setHistory(this.chatDisplay.histories[this.id]=c);},clearHistory:function(){CSS.addClass(this.tabHandle,'history_clearing');new AsyncRequest().setHandler(this._onClearHistoryResponse.bind(this)).setErrorHandler(this._onClearHistoryError.bind(this)).setTransportErrorHandler(this._onClearHistoryError.bind(this)).setData({clear_history_id:this.id}).setURI(this.chatDisplay.settingsURL).send();},_isCurrentPendingSend:function(a){return (this.pendingSentMsgs.length>0&&a==this.pendingSentMsgs[0].msgID);},_onSendInitialHandler:function(a){this.lastMessageHadOfflineResponse=false;},_onSendResponse:function(a,d){var b=d.getPayload();if(this._isCurrentPendingSend(a)){var c=this.pendingSentMsgs[0];c.asyncSuccess=true;}if(b&&b.warning){var e=this._renderMsgWarningMarkup(b.warning.title+'<br />'+b.warning.body);this._setMsgInfoMarkup(a,e,'msg_warning');}},_onSendTransportError:function(a,b){if(!this._isCurrentPendingSend(a))return;},_onSendError:function(i,k){if(!this._isCurrentPendingSend(i))return;var j=k.getPayload();var b=k.getError();var a=presence.getErrorDescription(k);if(b==kError_Chat_SendOtherNotAvailable){this.lastMessageHadOfflineResponse=true;buddyList.setUnavailable(this.id);for(var d=0;d<this.pendingSentMsgs.length;d++){var g=this.pendingSentMsgs[d];var h=ge('msg_'+this.id+'_'+g.msgID);if(h){var c='rel="dialog"';var l=new URI(this.chatDisplay.messageURL).addQueryData({id:this.id,message:g.text}).toString();var e=presence.renderLink(l,_tx("send as a message"),c);var f=_tx("{message} ({=send as a message})",{message:this._renderMsgHtmlize(g),'=send as a message':e});set_inner_html(h,f);}}}else if(b==kError_Chat_NotAvailable){this.lastMessageHadOfflineResponse=true;chatOptions.setVisibility(false);presence.doSync();}else if(b==kError_Chat_TooManyMessages){a=j.error.title;new ErrorDialog().showError(j.error.title,j.error.body);}else new ErrorDialog().showError(k.errorSummary,k.errorDescription);this._sendErrorAll(a);},_renderMsgWarningMarkup:function(a){return '<p class="chat_notice chat_msg_warning">'+a+'</p>';},_renderMsgErrorMarkup:function(a){return '<p class="chat_notice chat_msg_not_sent">'+a+'</p>';},_sendErrorAll:function(a){var b=this._renderMsgErrorMarkup(a);var c=true;while(this.pendingSentMsgs.length){var d=this.pendingSentMsgs.shift();d.isError=true;if(c)d.infoMarkup=b;this._setMsgInfoMarkup(d.msgID,b,'msg_error');this.failedSentMsgs.push(d);c=false;b='';}},_sendError:function(c,a){var b=this._renderMsgErrorMarkup(a);var d=this.pendingSentMsgs.shift();d.isError=true;d.infoMarkup=b;this._setMsgInfoMarkup(c,b,'msg_error');this.failedSentMsgs.push(d);this._popSendQueue();this._bumpSendingMessageDisplay(c);},_createMessage:function(c,e){var a=rand32()+1;var d=presence.getTime();if(this.lastLogItem&&d<this.lastLogItem.time)d=this.lastLogItem.time+1;var b={text:c,msgID:a,type:e,time:d,asyncSuccess:false,isError:false,errorMarkup:''};return b;},_flushSmallQueue:function(){if(this.pendingSentMsgs.length==1)this._sendMessage(this.pendingSentMsgs[0],!channelManager.iframeEverLoaded);},_updateChatActivity:function(b,a){this.lastLogItem={type:b.type,from:presence.user,to:this.id,time:b.time,msg:a};this.chatDisplay.chatActivityTime=(new Date()).getTime();presence.doSync();},sendInput:function(){var d=this.chatInput.value;if(!d||!d.match(/[^\s]/))return;if(this.actions.setVisible('clearHistory',true).refresh())this.handleResize();this.chatInput.value='';var b=this._createMessage(d,'msg');this.pendingSentMsgs.push(b);this._flushSmallQueue();var a={text:d};var c=this._renderMsg(presence.user,this.id,b.time,a,b.msgID);this._addConvMarkup(c);this._updateChatActivity(b,a);this._resetTypingState();},notifyTypingState:function(b){if(b!=this.typingRemoteState){this.typingRemoteState=b;presence.debug('tabs: notifyTyping('+b+')');if(!channelManager.iframeEverLoaded)return;var a={typ:b,to:this.id};new AsyncRequest().setHandler(bagofholding).setErrorHandler(bagofholding).setTransportErrorHandler(bagofholding).setData(a).setURI('/ajax/chat/typ.php').send();}},_sendMessage:function(f,h){f.time=presence.getTime();if(this.lastLogItem&&f.time<this.lastLogItem.time)f.time=this.lastLogItem.time+1;clearTimeout(this.sendingDisplayTimeout);clearTimeout(this.checkMessageSentTimeout);this.sendingDisplayTimeout=setTimeout(this._checkMessageSentShort.bind(this,f.msgID),this.sendingDisplayDelay);this.checkMessageSentTimeout=setTimeout(this._checkMessageSentLong.bind(this,f.msgID),this.sendingCheckDelay);if(h)return;var e=f.msgID;var b=this.chatDisplay.histories[this.id];var d=null;if(b)for(var c=b.length-1;c>0;c--)if(b[c].type=='msg'){d=b[c].time;break;}var g={msg_id:e,client_time:f.time,to:this.id,num_tabs:this.chatDisplay.numTabs,pvs_time:d};if(f.type=='video'){g.action=f.action;g.uid=f.uid;var a='/ajax/chat/video.php';}else{g.msg_text=f.text;var a='/ajax/chat/send.php';}if(typeof channelManager.expectResponse=='function')channelManager.expectResponse();new AsyncRequest().setInitialHandler(this._onSendInitialHandler.bind(this)).setHandler(this._onSendResponse.bind(this,e)).setErrorHandler(this._onSendError.bind(this,e)).setTransportErrorHandler(this._onSendTransportError.bind(this,e)).setData(g).setURI(a).send();},_popSendQueue:function(){if(this.pendingSentMsgs.length==0)return;var a=this.pendingSentMsgs[0];this._sendMessage(a);},_checkMessageSentShort:function(a){if(this._isCurrentPendingSend(a))this._setSendingDisplay(this.pendingSentMsgs[0]);},_checkMessageSentLong:function(a){if(this._isCurrentPendingSend(a))if(this.pendingSentMsgs[0].asyncSuccess){this._sendErrorAll(_tx("Could not connect to Facebook {Chat} at this time.",{Chat:_tx("Chat")}));}else if(channelManager.iframeIsLoaded){presence.error('tabs: send took too long; resending and invalidating old one');this._sendMessage(this.pendingSentMsgs[0]);}else{presence.error("tabs: send took too long, but iframe isn't yet loaded.  will check again later.");setTimeout(this._checkMessageSentLong.bind(this,this.pendingSentMsgs[0].msgID),this.sendingCheckDelay);}},_bumpSendingMessageDisplay:function(a){if(a==this.sendingDisplayMsgID){this._setMsgInfoMarkup(a,'');if(this.pendingSentMsgs.length>0)this._setSendingDisplay(this.pendingSentMsgs[0]);}},_setSendingDisplay:function(a){this.sendingDisplayMsgID=a.msgID;a.infoMarkup='<p class="chat_notice sending">'+_tx("Sending:")+'</p>';this._setMsgInfoMarkup(a.msgID,a.infoMarkup);},_setMsgInfoMarkup:function(e,b,c){var d=ge('msg_'+this.id+'_'+e);if(!d)return;var a=ge('pending_'+this.id+'_'+e);if(a)a.innerHTML=b;if(c)CSS.addClass(d,c);this.scrollToBottom();},updateUserInfo:function(){this.chatInfoPic.src=ChatUserInfos[this.id].thumbSrc;CSS.removeClass(this.chatInfo,'hidden');},tabHitAreaOnClick:function(){if(this.suppressHeaderCollapse)return;if(!presence.inVideoChat)if(presence.inPopoutWindow){this.chatDisplay.focusTab(this.id,this.name,this.firstName);}else this.chatDisplay.toggleTab(this.id,this.name,this.firstName);this.chatDisplay.doStopBlinking();},showChat:function(){if(presence.inVideoChat){animation(this.chatWrapper).to('right','0').duration(300).ease(animation.ease.end).go();animation(this.videochat_swf).to('marginRight','226px').duration(300).ease(animation.ease.end).go();this.arbiter.inform(ChatTab.TABMESSAGETYPE.DISPLAYCHAT,{visible:true});}},tabXOnClick:function(a){if(presence.inVideoChat){animation(this.chatWrapper).to('right','-228px').duration(300).ease(animation.ease.end).go();animation(this.videochat_swf).to('marginRight','0').duration(300).ease(animation.ease.end).go();this.arbiter.inform(ChatTab.TABMESSAGETYPE.DISPLAYCHAT,{visible:false});}else{this.chatDisplay.closeTab(this.id);this.chatDisplay.doStopBlinking();}$E(a).kill();return false;},headerLinkMouseOver:function(){CSS.addClass(this.chatHeader,'suppress_hover');this.suppressHeaderCollapse=true;},headerLinkMouseOut:function(){CSS.removeClass(this.chatHeader,'suppress_hover');this.suppressHeaderCollapse=false;},chatConvOnMouseDown:function(event){event=$E(event);if(event.button!=0)return;this.chatDisplay.doStopBlinking();},chatConvOnMouseUp:function(){if(DOM.getSelectionSupported()&&(DOM.getSelection()==''))this.focusChatInput();},focusChatInput:function(){if(!this.tabDisabled&&this.isTabVisible())this.chatInput.focus();},_buildUI:function(){var u='missed_count_'+this.id;var p='chat_window_wrapper_'+this.id;var d='chat_conv_'+this.id;var i='chat_history_error_'+this.id;var e='chat_header_'+this.id;var j='chat_info_'+this.id;var k='chat_info_pic_'+this.id;var c='chat_conv_content_'+this.id;var l='chat_input_'+this.id;var m='chat_shadow_input_'+this.id;var o='chat_toolbox_'+this.id;var a=_tx("Chat");var q=htmlize(this.trimName(this.maxHandleLen));var w=htmlize(this.trimName(this.maxTitleLen));var f=' onmouseover="'+this.tabRef+'.headerLinkMouseOver();" onmouseout="'+this.tabRef+'.headerLinkMouseOut();"';var t=this.chatDisplay.profileURL+'?id='+this.id;var h=presence.renderLink(t,'<img class="chat_info_pic" id="'+k+'" title="View Profile" style="display:block;">',f);var g=presence.renderLink(t,w,f);var v=['<div class="tab_button_div" ','onmouseover="CSS.addClass(this, \'hover\')" ','onmouseout="CSS.removeClass(this, \'hover\')">','<div title="',_tx("Show\/Hide {Chat} Window",{Chat:a}),'" ','class="tab_hit_area" ','onclick="',this.tabRef,'.tabHitAreaOnClick()">','<div class="tab_name">','<span>',q,'</span>','<img src="http://static.ak.fbcdn.net/images/spacer.gif"','class="tab_availability" alt="',q,'"/>','</div>','</div>','<div class="tab_count" id="',u,'"></div>','<div title="',_tx("Close {Chat} Window",{Chat:a}),'" ','class="tab_x" ','onclick="',this.tabRef,'.tabXOnClick(event)" ','onmouseover="CSS.addClass(this, \'hover\')" ','onmouseout="CSS.removeClass(this, \'hover\')">','</div>','<div class="chat_window_wrapper" id="',p,'">','<div class="chat_window">','<div class="chat_header" id="',e,'" onclick="',this.tabRef,'.tabHitAreaOnClick()">','<div class="header_buttons">','<a title="',_tx("Close {Chat} Window",{Chat:a}),'" ','class="close" ','onmouseover="CSS.addClass($(\'',e,'\'), \'suppress_hover\')" ','onmouseout="CSS.removeClass($(\'',e,'\'), \'suppress_hover\')" ','onclick="',this.tabRef,'.tabXOnClick(event)">','</a>','<a title="',_tx("Hide {Chat} Window",{Chat:a}),'" ','class="minimize">','</a>','</div>',h,'<div class="chat_header_name">',g,'</div>','</div>','<div class="chat_info" id="',j,'">','&nbsp;','</div>','<div id="',o,'" class="toolbox">','<div class="chat_actions"></div>','</div>','<div class="chat_conv" id="',d,'" ','onmousedown="',this.tabRef,'.chatConvOnMouseDown(event)" ','onmouseup="',this.tabRef,'.chatConvOnMouseUp()">','<div class="chat_notice" id="',i,'" style="display:none">',_tx("Couldn't retrieve chat history"),'</div>','<div class="chat_conv_content" id="',c,'"></div>','</div>','<div class="chat_input_div">','<textarea class="chat_shadow_input" id="',m,'"></textarea>','<div class="chat_input_icon"></div>','<textarea class="chat_input" id="',l,'" ','onclick="chatDisplay.doStopBlinking()" ','onkeydown="return ',this.tabRef,'.inputKeyDown(event)" ','onkeypress="return ',this.tabRef,'.inputKeyPress(event)" ','></textarea>','<div class="chat_input_border"></div>','</div>','</div>','</div>','</div>'];this.tabHandle=document.createElement('div');var n=ge('chat_tab_bar');var s=null;for(var r in this.chatDisplay.tabs)s=this.chatDisplay.tabs[r];if(s){n.insertBefore(this.tabHandle,s.tabHandle);}else n.appendChild(this.tabHandle);this.tabHandle.id='tab_handle_'+this.id;CSS.setClass(this.tabHandle,'tab_handle');this.tabHandle.style.width=this.handleWidth+'px';this.tabHandle.style.display='block';this.tabHandle.innerHTML=v.join('');this.tabCount=ge(u);this.chatWrapper=ge(p);this.chatConv=ge(d);this.chatHistoryError=ge(i);this.chatHeader=ge(e);this.chatInfo=ge(j);this.chatInfoPic=ge(k);this.chatConvContent=ge(c);this.chatInput=ge(l);this.chatShadowInput=ge(m);this.toolbox=ge(o);var b=DOM.find(this.toolbox,'div.chat_actions');this.actions=new ChatTabActions(b);this.actions.appendAction('clearHistory',_tx("Clear {Chat} History",{Chat:a}),this.clearHistory.bind(this));this.arbiter.inform(ChatTab.TABMESSAGETYPE.CREATETAB,{toolbox:this.toolbox});this.actions.refresh();this.popoutChatTabs=presence.inPopoutWindow?ge('open_chats'):null;this.adjustWrapperBottom();this._updateNumMissedDisplay();},adjustWrapperBottom:function(){if(presence.isFF2){var a=presence.getHolderBottomPosition();CSS.setStyle(this.chatWrapper,'bottom',(a+24)+'px');}},show:function(){this.tabHandle.style.display='block';},hide:function(){this.tabHandle.style.display='none';},inputKeyDown:function(event){event=$E(event);this.chatDisplay.doStopBlinking();if(this.chatDisplay.gatedFeatures.typ_send)this._updateTyping.bind(this).defer();if(event.keyCode==KEYS.RETURN&&!event.shiftKey)if(this.chatInput.value)this.sendInput();if(event.keyCode==KEYS.DELETE||event.keyCode==KEYS.BACKSPACE)this.handleResize.bind(this).defer();},inputKeyPress:function(event){event=$E(event);this.handleResize.bind(this).defer();if(event.keyCode==KEYS.RETURN&&!event.shiftKey){event.returnValue=false;return false;}},_updateTyping:function(){var a=this.typingState;if(this.chatInput.value.length==0){if(!(a==this.INACTIVE))this._typingTransition(this.INACTIVE);}else if(a==this.TYPING){this._recordKeystroke();}else if(a==this.INACTIVE){this._typingTransition(this.TYPING);this._recordKeystroke();}},_recordKeystroke:function(){this.typingLastKeystrokeAt=new Date();if(!this.typingCheckTimer)this.typingCheckTimer=setTimeout(this._checkTyping.bind(this),this.typingKeystrokeExpiry);},_checkTyping:function(){var a=this.typingLastKeystrokeAt.valueOf()+this.typingKeystrokeExpiry;var b=new Date().valueOf();if(b>a){this._typingTransition(this.INACTIVE);}else{clearTimeout(this.typingCheckTimer);this.typingCheckTimer=setTimeout(this._checkTyping.bind(this),a-b+10);}},_typingTransition:function(a){clearTimeout(this.typingCheckTimer);this.typingCheckTimer=null;typingLastKeystrokeAt=null;presence.debug('typing:'+this.typingState+' -> '+a);this.typingState=a;clearTimeout(this.typingNotifyTimer);this.typingNotifyTimer=setTimeout(this.notifyTypingState.bind(this,a),this.typingNotifyDelay);},_resetTypingState:function(){presence.debug('typing: ** RESET **');this.typingState=this.INACTIVE;this.typingRemoteState=this.INACTIVE;this.typingLastKeystrokeAt=null;clearTimeout(this.typingNotifyTimer);this.typingNotifyTimer=null;clearTimeout(this.typingCheckTimer);this.typingCheckTimer=null;},trimName:function(a){var b=this.name;if(b.length>a)b=b.substring(0,a-2)+'...';return b;},handleVisibility:function(b){var a=chatOptions.visibility;if(chatOptions.visibility){this._enableTab(true,false,a,b);}else this._disableTab(true,a,b);this.handleBuddyAvailability(!b&&a,b);},handleBuddyAvailability:function(b,c){if(!chatOptions.visibility)return;var a=buddyList.getAvailability(this.id);if(a){this._enableTab(false,a.i,b,c);}else this._disableTab(false,b,c);},_enableTab:function(b,a,c,d){d=d||false;var e=this.tabDisabled;this.tabDisabled=false;if(presence.inPopoutWindow){CSS.removeClass(this.popoutTab,'disabled');CSS.conditionClass(this.popoutTab,'idle',a);}CSS.removeClass(this.tabHandle,'disabled');CSS.conditionClass(this.tabHandle,'idle',a);if((b&&!d)||(!b&&e&&!c))this._newVisibilityChange(b,d,true);},_disableTab:function(a,b,c){c=c||false;var d=this.tabDisabled;this.tabDisabled=true;if(presence.inPopoutWindow){CSS.addClass(this.popoutTab,'disabled');CSS.removeClass(this.popoutTab,'idle');}CSS.addClass(this.tabHandle,'disabled');CSS.removeClass(this.tabHandle,'idle');if((a||c||!d)&&!this.lastMessageHadOfflineResponse&&!b)this._newVisibilityChange(a,c,false);},handleResize:function(){var g;var j;var h;var i;var d=31;var n=this.toolbox.childNodes;for(var e=0;e<n.length;++e){var c=n[e];if(shown(c))d+=Vector2.getElementDimensions(c).y;}if(presence.inVideoChat||presence.inPopoutWindow){var b=33;d+=Vector2.getElementDimensions(this.chatInfo).y-b;}if(presence.inVideoChat){var o=226;g=o;j=o-28;h=o-16;i=presence.popoutHeight-77;}else if(presence.inPopoutWindow){var k=(presence.popoutWidth>330)?presence.popoutWidth:330;g=k-this.flPopoutWidthOffset;j=k-this.flPopoutWidthOffset-28;h=k-this.flPopoutWidthOffset-16;var a=Vector2.getElementDimensions(ge('popout_chat_tabs')).y;i=presence.popoutHeight-a-33;}else{g=this.popinWidth;j=this.popinWidth-28;h=this.popinWidth-8;i=this.popinHeight;}this.chatShadowInput.style.width=this.chatInput.style.width=j+'px';this.chatShadowInput.value=this.chatInput.value;var m=this.chatShadowInput.scrollHeight;if(!m||presence.isOpera){m=this.minTextHeight;if(this.chatInput.value){var l=new RegExp('([\n]|[^\n]{'+parseInt(j/8)+'})','g');var f=this.chatInput.value.match(l);if(f)m=(f.length+1)*this.minTextHeight;}if(presence.isSafari2)m+=8;}if(ua.ie())m-=6;if(m>this.maxTextHeight){m=this.maxTextHeight;}else if(m<this.minTextHeight)m=this.minTextHeight;if(presence.isSafari2){d-=7;}else if(ua.ie()<7)if(this.tabDisabled)d+=4;if(!presence.inPopoutWindow||ua.ie()){this.chatHeader.style.width=g+'px';this.chatInfo.style.width=(g-55)+'px';this.chatConv.style.width=g+'px';}this.chatInput.style.height=m+'px';this.chatConv.style.height=Math.max(0,(i-d-m))+'px';this.scrollToBottom();},isUserScrolled:function(){return (this.chatConv.scrollHeight>this.chatConv.scrollTop+this.chatConv.clientHeight);},scrollToBottom:function(){this.chatConv.scrollTop=this.chatConv.scrollHeight;},unfocus:function(){this.focused=false;CSS.removeClass(this.tabHandle,'focused');},focus:function(b,a){if(this.focused)return;CSS.addClass(this.tabHandle,'focused');this.focused=true;if(!b){this._onFocusUIActions();setTimeout(this._onFocusUIActions.bind(this),100);}if(!this.historyLoaded)this.getHistory(false);this._updateNumMissed(0);this._stopBounce();},_onFocusUIActions:function(){this.handleResize();if(ua.ie()<7&&presence.inPopoutWindow)this.chatWrapper.style.top='67px';this.focusChatInput();},_startBounce:function(){if(presence.isFF2&&presence.isWindows)return;this.bounceAnimation=animation(this.tabCount).to('top',-11).duration(this.bounceDuration+40).checkpoint().to('top',this.bounceOrgPosition).duration(this.bounceDuration).checkpoint().to('top',-11).duration(this.bounceDuration+40).checkpoint().to('top',this.bounceOrgPosition).duration(this.bounceDuration).checkpoint().to('top',-7).duration(this.bounceDuration).checkpoint().to('top',-5).duration(this.bounceDuration).checkpoint().to('top',this.bounceOrgPosition).duration(this.bounceDuration).checkpoint().go();},_stopBounce:function(){if(this.bounceAnimation){this.bounceAnimation.stop();this.bounceAnimation=null;}},close:function(){this.tabHandle.parentNode.removeChild(this.tabHandle);this.closePopoutChat();},addPopoutChat:function(a){if(this.popoutChatTabs){this.popoutTab=document.createElement('div');this.popoutTab.id='popout_tab_'+this.id;this.popoutTab.className='popout_tab_button'+(this.chatDisplay.gatedFeatures.typ_show?'':' vanilla')+((a==this.chatDisplay.focused)?' highlight':'');var b='popout_missed_'+this.id;this.popoutTab.innerHTML='<div class="popout_tab_hit_area" onclick="'+this.tabRef+'.tabHitAreaOnClick();">'+'<div id="'+b+'" class="popout_tab_count"></div>'+'<div class="popout_tab_name">'+this.name+'</div>'+'<div class="popout_tab_status"></div>'+'<a class="popout_tab_x" href="#" onclick="'+this.tabRef+'.tabXOnClick(event)"></a>'+'</div>';this.popoutChatTabs.appendChild(this.popoutTab);this.popoutTabCount=ge(b);CSS.addClass(document.body,'active_chats');show(ge('popout_chat_tabs'));}},closePopoutChat:function(){if(this.popoutChatTabs){this.popoutChatTabs.removeChild(this.popoutTab);if(this.popoutChatTabs.childNodes.length<=0){hide(ge('popout_chat_tabs'));CSS.removeClass(document.body,'active_chats');}}},selectPopoutChat:function(){CSS.addClass(this.popoutTab,'highlight');},deselectPopoutChat:function(){CSS.removeClass(this.popoutTab,'highlight');},_newVisibilityChange:function(b,f,e){var h=presence.getTime();var g;if(b){if(e){g=_tx("You are online.",{name:this.firstName});}else g=_tx("You are not online.",{name:this.firstName});}else if(e){g=_tx("{name} is online.",{name:this.firstName});}else g=_tx("{name} is offline.",{name:this.firstName});var c={type:'online',time:h,text:g};var a=this.chatDisplay.getHistory(this.id,true);a.push(c);var d=this._renderVisibilityChange(h,g);this._addConvMarkup(d);this.lastLogItem=c;},newTyping:function(b){var a=b.from;var d=b.to;var e=b.st;if(!this.chatDisplay.gatedFeatures.typ_show){return;}else if((new Date()-this.lastMessageAt)<this.typingNotifyDelay)return;presence.debug('typing from '+a+': '+e);var c=(e==this.TYPING)&&(this.numMissed==0);if(d!=this.id){if(presence.inPopoutWindow)CSS.conditionClass(this.popoutTab,'typing',c);CSS.conditionClass(this.tabHandle,'typing',c);buddyList.setAvailable(this.id);}},_isChatMessage:function(a){return;typeof this.messageTypes[a.type]!='undefined'&&this.messageTypes[a.type].user;},newMsg:function(j){var c=j.from;var o=j.to;var p=j.type;var h=j.msg;var n=h.time;var a=h.clientTime;var i=h.msgID;var m=true;this.lastMessageAt=new Date();var d=this.chatDisplay.getHistory(this.id,true);var g=null;for(var f=d.length-1;f>=0;f--)if(this._isChatMessage(d[f])){g=d[f];break;}if(g&&n<=g.time){var b=false;for(var f=0;f<d.length;f++)if(this._isChatMessage(d[f])&&n==d[f].time){b=true;break;}if(b){presence.warn('tabs: already had this msg');return;}for(var f=d.length-1;f>=0;f--){var e=d[f];if(this._isChatMessage(e)&&(e.to!=o||(!e.msg.clientTime||e.msg.clientTime<a)))break;}presence.warn('tabs: merging new msg due to out-of-order server timestamp');if(f==d.length-1){this.chatDisplay.histories[this.id].push(j);}else{d.splice(f+1,0,j);this._setHistory(d);m=false;}}else this.chatDisplay.histories[this.id].push(j);if(o!=this.id){if(this.chatDisplay.gatedFeatures.sound&&chatOptions.getSetting('sound'))Sound.play('/sound/pop.mp3',true);buddyList.setAvailable(this.id);if(!this.focused){this._updateNumMissed(this.numMissed+1,n);this._startBounce();}if(presence.inPopoutWindow)CSS.removeClass(this.popoutTab,'typing');CSS.removeClass(this.tabHandle,'typing');}else{this._updateNumMissed(0,n);for(var f=0;f<this.pendingSentMsgs.length;f++)if(i==this.pendingSentMsgs[f].msgID){var l=this.pendingSentMsgs.splice(f,1);this._bumpSendingMessageDisplay(i);this._popSendQueue();m=false;break;}}this.arbiter.inform(ChatTab.TABMESSAGETYPE.RECEIVEMSG,{type:p,msgItem:j});m=this.messageTypes[p].visible&&m;if(m){var k=this._renderMsg(c,o,n,h);this._addConvMarkup(k);if(this.actions.setVisible('clearHistory',true).refresh())this.handleResize();this.lastLogItem=j;}},getInputElemId:function(){return 'chat_input_'+this.id;},_updateNumMissed:function(a,b){if(a==this.numMissed||(b&&b<=this.missedTime))return;if(a>99)a=99;this.numMissed=a;this.missedTime=b;this._updateNumMissedDisplay();},_updateNumMissedDisplay:function(){this.tabCount.innerHTML=this.numMissed;if(this.numMissed>0){if(this.popoutTabCount){this.popoutTabCount.style.display='block';this.popoutTabCount.innerHTML=this.numMissed;}else chatTabSlider.updateMissedCount();CSS.addClass(this.tabHandle,'highlight');this.tabCount.style.display='block';}else{if(this.popoutTabCount){this.popoutTabCount.style.display='none';}else chatTabSlider.updateMissedCount();CSS.removeClass(this.tabHandle,'highlight');this.tabCount.style.display='none';}},_addConvMarkup:function(b){var a=this.isUserScrolled();this.chatConvContent.innerHTML+=b;if(!a)this.scrollToBottom();},_renderDateBreak:function(f){var d=new Date();d.setTime(f);var e=false;var b=new Date();if(this.lastLogItem)b.setTime(this.lastLogItem.time);if(d.getDate()!=b.getDate()||d.getMonth()!=b.getMonth())e=true;var c='';if(e){var a='date_divider';if(!this.lastLogItem)a+=' first';c='<div class="'+a+'">'+renderDate(d,!presence.inPopoutWindow)+'</div>';}return c;},_renderVisibilityChange:function(b,c){var a=this._renderDateBreak(b);a+='<div class="visibility_change">'+'<span class="time_stamp">'+chatDisplay.renderServerTime(b)+'</span>'+c+'</div>';return a;},_renderMsg:function(b,p,n,g,l,e,a){var c=b!=this.id;var d=c&&b==p;var h=c&&!d?'self':'other';var f=this._renderDateBreak(n);if(!(!f&&this.lastLogItem&&this.lastLogItem.type=='msg'&&this.lastLogItem.from==b&&n-this.lastLogItem.time<this.msgBunchTime)){var q=ChatUserInfos[b];var m=q&&presence.inPopoutWindow?'<img src="'+q.thumbSrc+'" class="pic" />':'';var j=c?htmlize(presence.firstName):presence.renderLink(this.chatDisplay.profileURL+'?id='+this.id,htmlize(this.firstName));var o=chatDisplay.renderServerTime(n);f+='<h5 class="'+h+'">'+m+' <span class="time_stamp ts_'+h+'">'+o+'</span>'+j+'</h5>';}if(l||a){var k=l?' id="pending_'+this.id+'_'+l+'"':'';f+='<div'+k+' class="pic_padding">'+(a?a:'')+'</div>';}var i=l?' id="msg_'+this.id+'_'+l+'"':'';msgClasses='p_'+h+' pic_padding'+(e?' msg_error':'');f+='<p'+i+' class="'+msgClasses+'">'+this._renderMsgHtmlize(g)+'</p>';return f;},_renderMsgHtmlize:function(a){return html_hyperlink(a.text||'',this._processStyledText.bind(this,this.convTextEmoteProcessor),this.convTextProcessor,true);},_processStyledText:function(b,a){return b(a).replace(/\b_([^_\*]+)_\b/g,'<u>$1</u>').replace(/(\s|^)\*([^_\*]+)\*(?=$|\s)/g,'$1<b>$2</b>');},_processConvText:function(a){return html_wordwrap(a,this.convWrapLimit);},_processConvTextEmote:function(a){return Emote.htmlEmote(a,this.convTextProcessor);}});function renderDate(a,e){if(e){var f=new Date();f.setHours(0);f.setMinutes(0);f.setSeconds(0);f.setMilliseconds(0);var b=24*60*60*1000;var c=f.getTime()-a.getTime();if(c<=0){return _tx("Today");}else if(c<b)return _tx("Yesterday");}var d='';switch(a.getMonth()){case 0:d=_tx("January");break;case 1:d=_tx("February");break;case 2:d=_tx("March");break;case 3:d=_tx("April");break;case 4:d=_tx("May");break;case 5:d=_tx("June");break;case 6:d=_tx("July");break;case 7:d=_tx("August");break;case 8:d=_tx("September");break;case 9:d=_tx("October");break;case 10:d=_tx("November");break;case 11:d=_tx("December");break;}return _tx("{month} {date}",{month:d,date:a.getDate()});}
function ChatDisplay(e,b,a,c,d){this.histories=e;this.everSentMessage=b;this.user=presence.user;var f=env_get('www_base');this.profileURL=f+'profile.php';this.messageURL=f+'gigaboxx/dialog/MessageComposer.php';this.settingsURL='/ajax/chat/settings.php';this.gatedFeatures=d;this.useUICookieCache=d.ui_cookie_cache;this.renderServerTime=this.gatedFeatures['24h_times']?this._renderServerTime24hr:this._renderServerTime12hr;this._init(a,c);}ChatDisplay.prototype={blinkTime:1500,initialBlinkDelay:3000,_init:function(a,b){this.loaded=false;this.tabs={};this.numTabs=0;this.lastFocused=null;this.newMsgNames=[];this.newMsgNamesIndex=0;this.blinkingTimer=null;this.windowIsFocused=true;this.chatActivityTime=0;if(this.useUICookieCache){this.uiChangeTime=0;this.uiCookieCacheTime=(Env.rep_lag+presence.sitevars.CHAT_UI_COOKIE_CACHE_WINDOW)*1000;}this.favIcon=null;this.altFavIcon=null;this.initialFocusedChat=b;this.initialActiveChats=a;presence.registerStateStorer(this._store.bind(this));presence.registerStateLoader(this._load.bind(this));var c=['unfocus_chat','focus_chat','close_chat','msg','video','typ'].map(PresenceMessage.getArbiterMessageType);Arbiter.subscribe(c,this._handlePresenceMessage.bind(this));Arbiter.subscribe(PresenceMessage.STARTED,this.start.bind(this));Arbiter.subscribe(PresenceMessage.SHUTDOWN,this.shutdown.bind(this));Arbiter.subscribe(PresenceMessage.RESTARTED,this.restart.bind(this));Arbiter.subscribe(ChatOptions.VISIBILITY_CHANGED,this.handleVisibility.bind(this));Arbiter.subscribe(ChatBuddyList.AVAILABILITY_CHANGED,this._onBuddyAvailability.bind(this));Arbiter.subscribe(PresenceMessage.WINDOW_RESIZED,this.handleResize.bind(this));Event.listen(window,'focus',this.onWindowFocus.bind(this));Event.listen(window,'blur',this.onWindowBlur.bind(this));},onWindowFocus:function(){this.isWindowFocused=true;this.doStopBlinking();},onWindowBlur:function(){this.isWindowFocused=false;},start:function(){for(var a in this.tabs)this.tabs[a].start();},shutdown:function(){this._stopBlinking();},restart:function(){for(var a in this.tabs)this.tabs[a].restart();},loadInitialUserInfo:function(b,c,a){if(ChatUserInfos[b])return;ChatUserInfos[b]={name:c,firstName:a,thumbSrc:''};},_loadInitialTabs:function(a,d){var c=null;for(var e in a){if(presence.inVideoChat&&e!=presence.inVideoChatWith)continue;if(!c)c=e;if(this.tabs[e])continue;var i=a[e];var g,b;if(ChatUserInfos[e]){g=ChatUserInfos[e].name;b=ChatUserInfos[e].firstName;}else{g=i.n;if(!g)continue;b=i.fn?i.fn:getFirstName(g);}var h=i.m||0;var f=i.t||0;this.tabs[e]=new ChatTab(this,e,g,b,h,f);this.numTabs++;}if(presence.inVideoChat&&!c){d=presence.inVideoChatWith;}else if(presence.inPopoutWindow&&!d)d=c;if(d&&(d!=this.focused))this._focusTab(d);},load:function(){this._load(presence.state);},_load:function(d){var b=false;if(d){if(this.blinkingTimer&&d.sb)this._stopBlinking();this.chatActivityTime=verifyNumber(d.ct)*1000;if(this.useUICookieCache){var c=presence.getTime();this.uiChangeTime=Math.max(this.uiChangeTime,verifyNumber(d.uct)*1000);if(!this.loaded)if(c-this.uiChangeTime<this.uiCookieCacheTime){if(c-d.ut>60*60*1000)for(var a in d.t)d.t[a].m=0;presence.debug('chatDisplay: loading tabs from cookie cache');this._loadInitialTabs.bind(this,d.t,d.f).defer();b=true;}}}if(!this.loaded&&!b){presence.debug('chatDisplay: loading tabs from server state');this._loadInitialTabs.bind(this,this.initialActiveChats,this.initialFocusedChat).defer();this.initialFocusedChat=this.initialActiveChats=false;}this.loaded=true;},_store:function(c){c.ct=Math.floor(this.chatActivityTime*.001);c.sb=(this.blinkingTimer==null)?1:0;if(this.useUICookieCache){c.t={};c.f=null;c.uct=0;var b=presence.getTime();if(b-this.uiChangeTime<this.uiCookieCacheTime){for(var a in this.tabs){var d=this.tabs[a];c.t[a]={n:d.name,m:d.numMissed};if(d.firstName!=getFirstName(d.name))c.t[a].fn=d.firstName;}c.f=this.focused;c.uct=Math.floor(this.uiChangeTime*.001);}}return c;},handleResize:function(){if(!this.focused)return;var a=this.tabs[this.focused];a.handleResize();},_sendTabStateChange:function(a){a.window_id=presence.windowID;new AsyncRequest().setURI(this.settingsURL).setData(a).setHandler(this._onCheckTabStateChangeResponse.bind(this)).setErrorHandler(bagofholding).setTransportErrorHandler(bagofholding).send();},_onCheckTabStateChangeResponse:function(b){var a=b.getPayload();if(a.overlay)buddyList.addOverlayInfo(a.overlay);},reloadTabs:function(){for(var a in this.tabs)this.tabs[a].loadData();},_closeTab:function(b){if(!this.tabs[b])return;if(this.focused==b)if(presence.inPopoutWindow){var e=null;var a=false;for(var c in this.tabs)if(c!=b){e=c;if(a)break;}else if(e){break;}else a=true;if(e){var d=this.tabs[e];this._focusTab(e);}else this.focused=null;}else this.focused=null;this.tabs[b].close();delete this.tabs[b];this.numTabs--;chatTabSlider.close(b);},uiChanged:function(){if(this.useUICookieCache){this.uiChangeTime=presence.getTime();presence.doSync();}},closeTab:function(a){this._closeTab(a);this._sendTabStateChange({close_chat:a});this.uiChanged();},showVideoChatTab:function(){if(presence.inVideoChat)this.tabs[this.focused].showChat();},_unfocus:function(){if(!this.focused)return false;if(presence.inPopoutWindow)this.tabs[this.focused].deselectPopoutChat();this.tabs[this.focused].unfocus();this.focused=null;return true;},unfocus:function(){var a=this._unfocus();if(a){this._sendTabStateChange({unfocus_chat:1});this.uiChanged();}this.lastFocused=null;},unfocusNoSync:function(){this._unfocus();},refocus:function(){if(!this.lastFocused||!this.tabs[this.lastFocused])return null;this._focusTab(this.lastFocused);},_focusTab:function(b,d,a){if(b==this.focused||presence.inVideoChat&&b!=presence.inVideoChatWith)return;if(!this.tabs[b]){if(typeof d=='undefined'){if(!ChatUserInfos[b]||!ChatUserInfos[b].name){presence.warn("chat: couldn't create tab "+b+" since no name is specified");return;}d=ChatUserInfos[b].name;a=ChatUserInfos[b].firstName;}this.tabs[b]=new ChatTab(this,b,d,a,0);this.numTabs++;chatTabSlider.addTab(b);}chatTabSlider.gotoTab(b);if(this.focused){this.tabs[this.focused].unfocus();if(presence.inPopoutWindow)this.tabs[this.focused].deselectPopoutChat();}this.focused=b;this.lastFocused=b;if(this.focused){var c=this.loaded;(function(){var e=!presence.inPopoutWindow&&presence.poppedOut;if(this.tabs[this.focused])this.tabs[this.focused].focus(e,c);if(presence.inPopoutWindow)this.tabs[b].selectPopoutChat();}).bind(this).defer();}},focusTab:function(b,c,a){presence.pauseSync();this._focusTab(b,c,a);this._sendTabStateChange({focus_chat:b});this.uiChanged();this.chatActivityTime=(new Date()).getTime();this.doStopBlinking();presence.resumeSync();},toggleTab:function(b,c,a){if(this.focused==b){this.unfocus();}else this.focusTab(b,c,a);},doBlink:function(){if(!this.favIcon){var b=document.getElementsByTagName('link');for(var a=0;a<b.length;a++)if(b[a].rel=='shortcut icon'){this.favIcon=b[a];this.altFavIcon=document.createElement('link');this.altFavIcon.rel='shortcut icon';this.realTitle=document.title;break;}}if(this.favIcon.parentNode){if(this.newMsgNames&&this.newMsgNames.length>0){if(this.newMsgNamesIndex>=this.newMsgNames.length)this.newMsgNamesIndex=0;var c=this.newMsgNames[this.newMsgNamesIndex++];document.title=_tx("New message from {name}!",{name:c});}else document.title=_tx("New message!");var d=this.favIcon.parentNode;d.removeChild(this.favIcon);d.appendChild(this.altFavIcon);}else{document.title=this.realTitle;var d=this.altFavIcon.parentNode;d.removeChild(this.altFavIcon);d.appendChild(this.favIcon);}},doStopBlinking:function(a){if(this.blinkingTimer||a){this._stopBlinking();presence.doSync();}},_stopBlinking:function(){if(this.blinkingTimer){if(this.favIcon&&!this.favIcon.parentNode)this.doBlink();clearInterval(this.blinkingTimer);this.blinkingTimer=null;this.newMsgNames=[];this.newMsgNamesIndex=0;}},_onBuddyAvailability:function(b,a){this.handleBuddyAvailability(a.justCameOnline);},handleBuddyAvailability:function(b){for(var a in this.tabs)this.tabs[a].handleBuddyAvailability(b);},_handlePresenceMessage:function(h,a){var f=a.obj;if(f.window_id==presence.windowID)return;if(f.from){if(f.from==this.user){var d=f.to;}else var d=f.from;var g=this.tabs[d];}switch(f.type){case 'unfocus_chat':if(!presence.inVideoChat)this._unfocus();break;case 'focus_chat':if(!presence.inVideoChat)this._focusTab(f.id);break;case 'close_chat':if(!presence.inVideoChat)this._closeTab(f.id);break;case 'msg':case 'video':if(this.inVideoChat&&(f.from==presence.inVideoChatWith||f.to==presence.inVideoChatWith))break;if(f.from==this.user){var e=f.to_name;var b=f.to_first_name?f.to_first_name:getFirstName(e);}else{var e=f.from_name;var b=f.from_first_name?f.from_first_name:getFirstName(e);}this.loadInitialUserInfo(d,e,b);var c=(f.from==this.user);buddyList.setAvailable(d,c);if(!g){g=this.tabs[d]=new ChatTab(this,d,e,b,0);this.numTabs++;chatTabSlider.addTab(d);if(!this.focused){this.focusTab(d);}else g.getHistory();}if(presence.inPopoutWindow||!presence.poppedOut)if(c){this.doStopBlinking(true);}else if(this.isWindowFocused){setTimeout(this.doStopBlinking.bind(this,true),500);}else if(!presence.isOpera){this.newMsgNames.push(g.firstName);if(!this.blinkingTimer)this.blinkingTimer=setTimeout(function(){this.blinkingTimer=setInterval(this.doBlink.bind(this),this.blinkTime);}.bind(this),this.initialBlinkDelay);}f.time=f.msg.time;g.newMsg(f);break;case 'typ':if(g){g.newTyping(f);}else presence.debug('typing message ignored');break;default:break;}},handleVisibility:function(){for(var a in this.tabs)this.tabs[a].handleVisibility();},getHistory:function(b,a){a=a||false;if(!this.histories[b]&&a)this.histories[b]=[];return this.histories[b];},_renderServerTime12hr:function(d){var e=new Date();e.setTime(d+presence.timeSkew);var b=e.getHours();var a='am';if(b>=12){a='pm';b-=12;}if(b==0)b=12;var c=e.getMinutes();if(c<10)c='0'+c;var f=b+':'+c+a;return f;},_renderServerTime24hr:function(c){var d=new Date();d.setTime(c+presence.timeSkew);var a=d.getHours();if(a<10)a='0'+a;var b=d.getMinutes();if(b<10)b='0'+b;var e=a+':'+b;return e;}};function chat_simple_popout(){window.open(presence.popoutURL,"fbChatWindow","status=0,toolbar=0,location=0,menubar=0,"+"directories=0,resizable=1,scrollbars=0,"+"width="+Presence.prototype.defWidth+",height="+Presence.prototype.defHeight+",left="+Presence.prototype.defX+",top="+Presence.prototype.defY);}
function ChatBuddyListTypeahead(d,c,b,a){this.curStr='';this.clearDiv=null;this.focused=false;this.selected=null;this.selectedIndex=0;this.selectableCount=0;this.minBuddyCount=buddyList.flMode?20:10;this.flid=b;this.excludedIds=a;this.id=ChatBuddyListTypeahead.numTypeaheads++;this.obj=d;this.obj.typeahead=this;this.placeholderText=d.value;this.inputDiv=c;this.shouldShowClear=!presence.isSafari2;if(!this.shouldShowClear)d.onmousedown=this._onmousedown.bind(this);addEventBase(this.obj,'focus',this._onfocus.bind(this));addEventBase(this.obj,'blur',this._onblur.bind(this));addEventBase(this.obj,'keyup',function(e){e=$E(e);var f=e?e.keyCode:-1;this._onkeyup.bind(this,f).defer();}.bind(this));this.captureSubmit();this.buildIndex();Arbiter.subscribe(ChatBuddyList.AVAILABILITY_CHANGED,this.buildIndex.bind(this));}ChatBuddyListTypeahead.numTypeaheads=0;ChatBuddyListTypeahead.mixin({buildIndex:function(){this.availableListIDs=buddyList.getSortedListUI(this.flid);this.firstLetterIndex={};for(var a=0;a<this.availableListIDs.length;a++){var b=this.availableListIDs[a];var c=typeahead_source.tokenize(ChatUserInfos[b].name);for(var d=0;d<c.length;d++){if(!this.firstLetterIndex[c[d][0]])this.firstLetterIndex[c[d][0]]={};this.firstLetterIndex[c[d][0]][b]=true;}}this._refreshAvailableList();if(buddyList.availableCount<this.minBuddyCount){hide(this.inputDiv);this.resetSearch(true);}else{show(this.inputDiv);this.search.bind(this,true).defer();}},_onfocus:function(a){this.focused=true;this.captureSubmit();},_onblur:function(a){this.focused=false;if(this.curStr=='')this.hideClear();},_getAvailableListIDs:function(){if(!this.availableIDs)this._refreshAvailableList();return this.availableIDs;},_refreshAvailableList:function(){var a=this.availableListIDs;if(this.excludedIds)a=a.filter((function(b){return this.excludedIds[b]!=1;}).bind(this));this.availableIDs=a;},_onmousedown:function(){setTimeout(function(){this._onkeyup(0);}.bind(this),100);},_onkeyup:function(a){switch(a){case KEYS.ESC:if(''==this.curStr){buddyList.closeTab();}else this.resetSearch(true);break;case undefined:case KEYS.LEFT:case KEYS.RIGHT:return false;break;case KEYS.UP:this.upArrowPress();break;case KEYS.DOWN:this.downArrowPress();break;case KEYS.RETURN:this.select();break;case KEYS.BACKSPACE:case 0:default:if(this.search())this.resetSearch(true);break;}},focusInput:function(){if(buddyList.availableCount&&buddyList.availableCount>this.minBuddyCount)this.obj.focus();this.resetSearch();},captureSubmit:function(){if((!this.capturedForm||this.capturedSubstitute!=this.capturedForm.onsubmit)&&this.obj.form){this.capturedForm=this.obj.form;this.captured_event=this.obj.form.onsubmit;this.capturedSubstitute=this.obj.form.onsubmit=function(){return false;}.bind(this.obj.form);}},resetSearch:function(a){if(!this.obj)return false;if(!this.obj.value||a){this.curStr='';this.obj.value='';this.hideClear();}this.selected=null;this.selectedIndex=-1;this.showAll();this.hideClear();buddyList.unfreezeTabSize();},search:function(a){var e=this.obj.value;if(e==this.placeholderText)return true;var c=typeahead_source.flatten_string(e);if(!a&&c==this.curStr)return false;this.curStr=c;var d=typeahead_source.tokenize(c).sort(typeahead_source._sort);if(!d[0])return true;var b=this.firstLetterIndex[d[0][0]];buddyList.freezeTabSize();this.showClear();buddyList.suppressNonFriendInfoInBuddyList(this.flid);this.getMatchingFriends(b,d);this.selected=null;this.selectMatchingFriends();return false;},getMatchingFriends:function(h,i){var f=0;var b;var a=this._getAvailableListIDs();for(var d=0;d<a.length;d++){var e=a[d];var c=ChatUserInfos[e].name;if(h!=undefined&&h[e]&&typeahead_source.check_match(i,c)){var g=typeahead_source.highlight_found(c,this.curStr);buddyList.getBuddyItemName(e,this.flid).setContent(HTML(g));buddyList.showBuddyItem(e,false,this.flid);f++;if(!b)b=e;}else{CSS.removeClass(buddyList.getBuddyItem(e,this.flid),'selected');buddyList.hideBuddy(e,this.flid);}}if(f>0){buddyList.hideEmptySearch(this.flid);if(f==1||(i.length==1&&i[0].length==1)){this.selected=b;this.selectedIndex=0;CSS.addClass(buddyList.getBuddyItem(b,this.flid),'selected');}}else buddyList.showEmptySearch(this.flid);},selectMatchingFriends:function(){this.selectableCount=0;var a=this._getAvailableListIDs();for(var c=0;c<a.length;c++){var d=a[c];var b=buddyList.getBuddyItem(d,this.flid);if(b&&CSS.getStyle(b,'display')!='none'){if(this.selectedIndex==this.selectableCount){this.selected=d;CSS.addClass(b,'selected');Vector2.scrollIntoView(b);}else CSS.removeClass(b,'selected');this.selectableCount++;}}},downArrowPress:function(){this.selectedIndex++;var a=this.selectableCount-1;if(this.selectedIndex>a)this.resetSearch();this.selectMatchingFriends();},upArrowPress:function(){this.selectedIndex--;if(this.selectedIndex<0)this.selectedIndex=0;this.selectMatchingFriends();},showAll:function(){this.obj.value='';buddyList.hideEmptySearch(this.flid);var a=this._getAvailableListIDs();for(var c=0;c<a.length;c++){var d=a[c];var b=buddyList.getBuddyItem(d,this.flid);if(b){buddyList.updateBuddyItemName(d,this.flid);CSS.removeClass(buddyList.getBuddyItem(d,this.flid),'selected');buddyList.showBuddyItem(d,true,this.flid);}}buddyList.unsuppressNonFriendInfoInBuddyList(this.flid);},showClear:function(){if(this.clearDiv==null&&this.shouldShowClear){this.clearDiv=document.createElement('div');this.clearDiv.setAttribute('id','clear_search'+this.id);DOM.setContent(this.clearDiv,HTML('<a href="#" class="hide"></a>'));var a=DOM.find(this.clearDiv,'a');a.listen('click',(function(){this.resetSearch(true);return false;}).bind(this));this.inputDiv.appendChild(this.clearDiv);}},hideClear:function(){if(ge('clear_search'+this.id)){this.clearDiv=null;this.inputDiv.removeChild(ge('clear_search'+this.id));}},select:function(){if(this.selected!=null){CSS.removeClass(buddyList.getBuddyItemName(this.selected,this.flid),'selected');buddyList.itemOnClick(this.selected,this.flid);this.resetSearch(true);}}});
function PresenceUpdater(){this.timerGranularity=presence.sitevars.UPDATE_GRANULARITY?presence.sitevars.UPDATE_GRANULARITY*1000:60000;this._init();}PresenceUpdater.prototype={_init:function(){this.handlers=[];this.updatePaused=0;this.updateNumber=0;this._runTimer();bind(Arbiter,Arbiter.inform,PresenceMessage.PRESENCE_UPDATER_READY,true,Arbiter.BEHAVIOR_STATE).defer();},register:function(a,b,d,c,e){this.handlers.push({asyncParam:a,checkCB:b,responseCB:d,errorCB:c,transportErrorCB:e});},_runTimer:function(){clearTimeout(this.timer);this.timer=setTimeout(this.checkForUpdate.bind(this,false,[],false),this.timerGranularity);},forceUpdate:function(a){if(this.updatePaused)return;if(a!==undefined&&a.length>0){this.checkForUpdate(false,a,false);}else this.checkForUpdate(true,[],false);},pauseUpdate:function(){this.updatePaused++;},resumeUpdate:function(a){this.updatePaused--;this.forceUpdate(a);},checkForUpdate:function(d,e,c){if(!c)clearTimeout(this.timer);if(presence.isShutdown){if(!c)this._runTimer();return;}var j=presence.getTime();var b=[];var a={user:presence.user};for(var h=0;h<this.handlers.length;h++){var g=this.handlers[h];var f=d||(e.indexOf(g.asyncParam)!=-1);var i=g.checkCB(j,a,f);if(i){a[g.asyncParam]=1;b.push(g);}}if(b.length>0){this._sendUpdate(a,b,c);}else if(!c)this._runTimer();},runHandler:function(a){this.checkForUpdate(false,[a],true);},_initialHandler:function(b,a){if(b!=this.updateNumber)return false;},_onResponse:function(a,b,f){var g=f.getPayload();presence.updateServerTime(g.time);var h=presence.getTime();for(var d=0;d<a.length;d++){var c=a[d];var e=g[c.asyncParam];if(typeof e=='undefined'||!e){c.errorCB(f);}else c.responseCB(e,h);}presenceCookieManager.store();if(!b)this._runTimer();},_onError:function(a,c){for(var b=0;b<a.length;b++)a[b].errorCB(c);this._runTimer();},_onTransportError:function(a,c){for(var b=0;b<a.length;b++)a[b].transportErrorCB(c);this._runTimer();},_sendUpdate:function(a,b,c){this.updateNumber++;var f=a.notifications?'/ajax/presence/update.php':'/ajax/chat/buddy_list.php';var e=URI.getRequestURI().getQueryData();var d={};for(key in e)if(key.indexOf('buddy')==0)d[key]=e[key];if(d)f=new URI(f).setQueryData(d);this.async=new AsyncRequest().setInitialHandler(this._initialHandler.bind(this,this.updateNumber)).setHandler(this._onResponse.bind(this,b,c)).setErrorHandler(this._onError.bind(this,b)).setTransportErrorHandler(this._onTransportError.bind(this,b)).setOption('suppressErrorAlerts',true).setData(a).setURI(f).send();}};
function ChatBuddyList(){this.user=presence.user;this.shouldRender=true;this.haveFullList=false;this.errorMode=false;this.shouldShowLoading=false;this.availableCount=0;this.availableList={};this.sortedList=[];this.listChanged=false;this.updateTime=0;this.flMode=false;this.flData={};this.otherFriendsFlid='-1';this.botsFlid='-2';this.stopUpdates=false;this.flSortableGroup=null;this.reorderingLists=false;this.sortables={};this.flOpts={};this.externalFlids=[];this.updateOverlay={};this.visibilityRatio={};this.justCameOnline=false;this.maxNameLen=20;this.backgroundColor='#fff';}copy_properties(ChatBuddyList,{OVERLAY_ONLINE:0,OVERLAY_IDLE:1,OVERLAY_OFFLINE:-1,DEFAULT_OPTS:{fullDisplay:true,excludeIds:{}},BUDDY_LIST_INITIALIZED:'buddylist/initialized',BUDDY_CLICKED:'buddylist/buddy_clicked',AVAILABILITY_CHANGED:'buddylist/availability-changed',UPDATER_NAME:'buddy_list'});ChatBuddyList.prototype={maxItemsToAnimate:10,highlightColor:'#fffbe2',expandAnimDuration:400,compactItemHeight:20,fullItemHeight:26,initError:function(){this.errorMode=true;this._init();},initNoRender:function(a,b,g,e,d,c,f){this.shouldRender=false;this.shouldShowLoading=true;this.availableCount=a;this.availableList=b;this.updateTime=g;this.listChanged=e;this.updateOverlay=f;this.flMode=d;this.flData=c;this._init();if(presence.inPopoutWindow)this._forceUpdate.bind(this,false).defer();},initFullList:function(a,f,d,c,b,e){this.availableList=a;this.updateTime=f;this.listChanged=d;this.haveFullList=true;this.flMode=c;this.flData=b;this.updateOverlay=e;this.availableCount=count(this.availableList);this._init();},_init:function(){this.loaded=false;this.poppedOut=presence.poppedOut;this.buddyListOpen=false;this.updateDiff=0;this.rendered=false;this.showingError=false;this.numRequestFailures=0;for(var a in this.availableList)this.availableList[a].i=this.availableList[a].i?1:0;this.tabID='buddy_list_tab';this.wrapperID='buddy_list';this.contentID='buddy_list_content';this.tabDiv=ge(this.tabID);this.wrapperDiv=ge(this.wrapperID);this.contentDiv=ge(this.contentID);this.buddyListError=ge('buddy_list_error');this.buddyCountSpan=ge('buddy_count');presenceUpdater.register(ChatBuddyList.UPDATER_NAME,this._checkUpdater.bind(this),this._onUpdaterResponse.bind(this),this._onUpdaterError.bind(this),this._onUpdaterError.bind(this));presenceCookieManager.register('bl',this._getCookieData.bind(this));presence.registerStateStorer(this._storeState.bind(this));presence.registerStateLoader(this._loadState.bind(this));Arbiter.subscribe(PresenceMessage.getArbiterMessageType('fl_settings'),this._handleFLMessage.bind(this));Arbiter.subscribe(ChatOptions.VISIBILITY_CHANGED,this._handleVisibility.bind(this));this.setCompactDisplay(chatOptions.getSetting('compact_buddylist'));this._loadState(presence.state);this._postInit.bind(this).defer();Arbiter.subscribe(Arbiter.LIST_EDITOR_LISTS_CHANGED,this._flManagerHandler.bind(this));},_postInit:function(){if(presence.inPopoutWindow)this._firstRender();if(chatOptions.visibility)this._updateCount();this.updateDiff=this._computeUpdateTimeDiff();this._mergeOverlay();Arbiter.inform(ChatBuddyList.BUDDY_LIST_INITIALIZED,{},Arbiter.BEHAVIOR_PERSISTENT);},_storeState:function(a){a.blo=this.buddyListOpen?1:0;a.bvt=parseInt(this.buddyViewTime*.001);return a;},_loadState:function(c){this.buddyViewTime=verifyNumber(c.bvt)*1000;var b=!!c.blo;if(!presence.poppedOut&&this.poppedOut){this._showLoading();this._forceUpdate(false);}this.poppedOut=presence.poppedOut;var a=null;if(!this.poppedOut)if(b){a=this.openTab.bind(this);}else a=this.closeTab.bind(this);if(a)if(this.loaded){a();}else a.defer();this.loaded=true;},setCompactDisplay:function(a){this.isCompactDisplay=a;if(this.isCompactDisplay){this.itemHeight=this.compactItemHeight;}else this.itemHeight=this.fullItemHeight;if(this.rendered)this._render();},_handleVisibility:function(){if(chatOptions.visibility){this._showLoading();this._show();this._forceUpdate(true);this.justCameOnline=true;}else this._hide();},_handleFLMessage:function(c,a){var b=a.obj;this.setVisibilityRatio({});if(!this._flChanged(b.fl_mode,b.fl_data))return;this._onFlChange(b.fl_mode,b.fl_data);},_flChanged:function(b,a){return (b!=this.flMode||!are_equal(a,this.flData));},_massageNowAvailableList:function(h,g,f){for(var e in h){var a=h[e];if(g!=this.flMode){if(g){delete a.fl;}else a.fl=[this.otherFriendsFlid];}else{var c=a.fl||[];for(var d=0;d<c.length;d++){var b=c[d];if(typeof this.flData[b]=='undefined')a.fl.remove(b);}if(a.fl&&a.fl.length==0)a.fl=[this.otherFriendsFlid];}h[e]=a;}return h;},_onFlChange:function(d,c){if(!this.rendered){this.flMode=d;this.flData=c;return;}var g=[];var h=[];var f=[];var e=[];if(this.flMode&&this.flMode==d){var b=this._groupAvailableListByFl(true);for(var a in c)if(typeof this.flData[a]=='undefined'){if(c[a].h)continue;g.push(a);f.push(a);}else if(this.flData[a].h!=c[a].h){if(c[a].h){h.push(a);}else{g.push(a);if(c[a].o)f.push(a);}}else if(this.flData[a].o!=c[a].o)if(c[a].o){f.push(a);}else e.push(a);for(var a in this.flData)if(typeof c[a]=='undefined')h.push(a);this.flMode=d;if(h.length!=0)this._removeFlidsFromBuddyList(h,b);if(e.length!=0)this._goOfflineToLists(e,true);this.flData=c;if(g.length!=0)this._addFlidsToDOM(g,b);if(f.length!=0)this._goOnlineToLists(f,true);}else if(this.flMode&&this.flMode!=d){var b=this._groupAvailableListByFl(true);h=keys(this.flData);this.flMode=d;this.flData=c;this._addFlidsToDOM([null]);this._removeFlidsFromBuddyList(h,b);this._forceUpdate(false);}else{for(var a in c){if(c[a].h)continue;g.push(a);if(c[a].o)f.push(a);}this.flMode=d;this.flData=c;this._removeFlidsFromDOM([null]);if(g.length>0)this._addFlidsToDOM(g);if(f.length>0)this._goOnlineToLists.bind(this,f,true).defer();}},_addFlidsToDOM:function(e,f){f=f||this._groupAvailableListByFl(true);var a=this._getRenderedFriendLists();var c=a[0];var h=$('buddy_list_parent');for(var g=0;g<e.length;g++){var d=e[g];if(this.flMode&&d){var b=DOM.create('div',{id:this._getFriendListId(d),className:this._getFriendListItemClasses(d,f)});DOM.setContent(b,HTML(this._renderFriendListHeader(d)));DOM.appendContent(b,HTML(this._renderFriendListContent(d,[])));if(c==d){h.prependContent(b);}else{var j=a.indexOf(d);var i=a[j-1];DOM.insertAfter(ge(this._getFriendListId(i)),b);}this._addFlSortable(d);this._initFlidSortable(d,[]);}else h.prependContent(HTML(this._renderFriendListContent(null,[])));}this._addFriendListListeners(e);},_removeFlidsFromDOM:function(b){for(var c=0;c<b.length;c++){var a=b[c];if(a){if(ge(this._getFriendListId(a))){DOM.remove($(this._getFriendListId(a)));this._removeFlSortable(a);this._destroyFlidSortable(a);}}else{DOM.remove($(this._getAvailableMarkerId(a)));DOM.remove($(this._getIdleMarkerId(a)));}}},loadTypeahead:function(){this.typeahead=new ChatBuddyListTypeahead($("buddy_list_typeahead_input"),$("buddy_list_typeahead"));},getContentWrapper:function(){return this.contentDiv.parentNode;},resizeTab:function(a){if(this.resizeFrozen)if(a){this.resizeFrozen=false;}else return;presence.tabContentResize(this.wrapperID,this.contentID);},freezeTabSize:function(a){if(this.resizeFrozen||this.showingError)return;this.resizeFrozen=true;if(a===undefined)a=true;presence.tabContentResize(this.wrapperID,this.contentID,a);},unfreezeTabSize:function(){if(!this.resizeFrozen)return;this.resizeFrozen=false;this.resizeTab();presence.contentChanged(this.contentID);},_hide:function(){if(!presence.inPopoutWindow){CSS.addClass(presence.holder,'buddy_list_hidden');this.closeTab();DOM.setContent(this.buddyCountSpan,_tx("Chat (Offline)"));}},_show:function(){if(presence.inPopoutWindow){CSS.removeClass(presence.popoutSidebar,'buddy_list_hidden');}else{CSS.removeClass(presence.holder,'buddy_list_hidden');this.openTab();this._updateCount();}},toggleTab:function(){if(!this.buddyListOpen){this.openTab(true);}else this.closeTab();},_goOnline:function(){chatOptions.sendVisibility(true);},openTab:function(b){if(this.buddyListOpen)return;if(CSS.hasClass(presence.holder,'buddy_list_hidden')){this._goOnline();return;}if(!this.rendered){var a=this.availableList;this.availableList={};this.shouldShowLoading=true;this._firstRender();presence.openTab(this.wrapperID,this.tabID);this.availableList=a;if(this.haveFullList){this._render.bind(this).defer();setTimeout(this._availableListChanged.bind(this,true),10);}}else presence.openTab(this.wrapperID,this.tabID,this.contentID);this.buddyListOpen=true;setTimeout(this._openTabPostProcess.bind(this,b),50);},_openTabPostProcess:function(a){this.buddyViewTime=(new Date()).getTime();var b=(presence.getTime()-this.updateTime)*.001;if(this.showingError||b>presence.sitevars.BUDDY_VIEW_FETCH_WINDOW)this._forceUpdate(false);presence.doSync();if(a&&this.typeahead)this.typeahead.focusInput();},closeTab:function(){if(!this.buddyListOpen)return;this.buddyListOpen=false;presence.toggleTab(this.wrapperID,this.tabID,this.contentID);if(chatOptions.visibility)setTimeout(this._closeTabPostProcess.bind(this),50);buddyListDisplay.closeOpenFlyout();this.exitReorderingFlMode();},_closeTabPostProcess:function(){if(this.typeahead)this.typeahead.resetSearch(true);this.buddyViewTime=(new Date()).getTime();presence.doSync();},_mergeOverlay:function(){if(!this.haveFullList)return;var d=presence.getTime();var c={};var e=[];for(var b in this.updateOverlay)if(d<this.updateOverlay[b].exp){var a=this.availableList[b];if(!ChatUserInfos[b])continue;if(this.updateOverlay[b].ol!=ChatBuddyList.OVERLAY_OFFLINE){if(!a){a={i:0};if(this.flMode)a.fl=[this.otherFriendsFlid];c[b]=a;}}else e.push(b);}else delete this.updateOverlay[b];if(!is_empty(c)||!is_empty(e))this._updateAvailableListWithDiff(c,e);},getAvailability:function(a){if(a==this.user)return chatOptions.visibility;if(typeof this.availableList[a]!='undefined'){return this.availableList[a];}else return null;},setAvailable:function(a,b){this._manageOverlay(a,ChatBuddyList.OVERLAY_ONLINE);this._addToBuddyList([a],b);},_addToBuddyList:function(e,f){var a={};var g=[];for(var c=0;c<e.length;c++){var d=e[c];var b=this.getAvailability(d);if(b&&(b.i==0||f))continue;a[d]={i:0};if(this.flMode)if(this.availableList[d]&&this.availableList[d].fl){a[d].fl=this.availableList[d].fl;}else a[d].fl=[this.otherFriendsFlid];if(b&&b.i==1)g.push(d);}this._updateAvailableListWithDiff(a,g);},setFlids:function(b,a){if(!this.getAvailability(b))return;if(this.availableList[b].fl[0]==this.otherFriendsFlid){var c={};c[b]=this.availableList[b];c[b].fl=a;this._updateAvailableListWithDiff(c,[],this.otherFriendsFlid);}},setUnavailable:function(a){this._manageOverlay(a,ChatBuddyList.OVERLAY_OFFLINE);this._removeFromBuddyList([a]);},_removeFromBuddyList:function(d,a){var e=[];for(var b=0;b<d.length;b++){var c=d[b];if(!this.getAvailability(c))continue;e.push(c);}if(e.length>0)this._updateAvailableListWithDiff({},e,a);},addOverlayInfo:function(b){for(var a in b)this._manageOverlay(a,b[a].ol);this._mergeOverlay();},_manageOverlay:function(b,c){var a=presence.getTime()+60000;this.updateOverlay[b]={ol:c,exp:a};if(this.rendered)presenceCookieManager.store();},hideBuddy:function(c,a){var b;if(a){b=[a];}else b=this._getUserFlids(c,null,true);this._toggleBuddy(c,false,b);},_toggleBuddy:function(e,h,c){var g=h?'block':'none';var f,a;for(var d=0;d<c.length;d++){var b=c[d];f=ge(this._getBuddyListItemId(e,b));if(f)f.style.display=g;if(h&&(a=ge(this._getFriendListId(b))))CSS.removeClass(a,'suppress');}},showBuddyItem:function(d,e,a){e=e||false;var b;if(a){b=[a];}else{var b=this._getUserFlids(d,null,true);if(b.length>1&&!e){var c=b.slice(1);this._toggleBuddy(d,false,c);b=[b[0]];}}this._toggleBuddy(d,true,b);},getBuddyItem:function(b,a){a=this._getUserFlid(b,a);return ge(this._getBuddyListItemId(b,a));},getBuddyItemName:function(b,a){a=this._getUserFlid(b,a);return ge(this._getBuddyListItemNameId(b,a));},updateBuddyItemName:function(b,a){var e=ChatUserInfos[b];var c=e.name;var d;if(c.length>this.maxNameLen){d=c.substring(0,this.maxNameLen-2)+'...';}else d=c;this.getBuddyItemName(b,a).innerHTML=d;},_getUserFlid:function(c,a){if(a===null||a===undefined){var b=this._getUserFlids(c);a=b[0];}return a;},showEmptySearch:function(a){show(this._getEmptySearchId(a));},hideEmptySearch:function(a){hide(this._getEmptySearchId(a));},_getSortedList:function(){if(this.sortedList.length==0&&count(this.availableList)==this.availableCount){this._pruneUsersWithoutDisplayInfo(this.availableList);this.sortedList=this._sort(keys(this.availableList));}return this.sortedList;},_pruneUsersWithoutDisplayInfo:function(a){for(var b in a)if(!ChatUserInfos[b])delete a[b];},getSortedListUI:function(a){if(!a&&this.flMode){var b=this._groupAvailableListByFl(true);var c=[];for(var a in b)c=c.concat(b[a]);return unique(c);}return this._getSortedList();},getFriendLists:function(){var a={};copy_properties(a,this.flData);delete a[this.otherFriendsFlid];delete a[this.botsFlid];return a;},_getRenderedFriendLists:function(){var b=[];for(var a in this.flData)if(!this.flData[a].h)b.push(a);return b;},_getFriendListsInChat:function(){var a=this._getRenderedFriendLists();a.remove(this.otherFriendsFlid);a.remove(this.botsFlid);return a;},suppressNonFriendInfoInBuddyList:function(a){this._updateNonFriendInfoInBuddyList(a,true);},unsuppressNonFriendInfoInBuddyList:function(a){this._updateNonFriendInfoInBuddyList(a,false);},_updateNonFriendInfoInBuddyList:function(b,f){var c=b?[b]:this._getGlobalFlids(true);var e,a;for(var d=0;d<c.length;d++){var b=c[d];if(e=ge(this._getIdleMarkerId(b)))CSS.conditionClass(e,'suppress',f);if(b&&(a=ge(this._getFriendListId(b))))CSS.conditionClass(a,'suppress',f);}},_updateCount:function(){if(this.buddyCountSpan&&!presence.inPopoutWindow){var a=_tx("{Chat} {number-available}",{Chat:_tx("Chat"),'number-available':'<span class="buddy_count_num">(<strong>'+this.availableCount+'</strong>)</span>'});this.buddyCountSpan.innerHTML=a;}},setVisibilityRatio:function(a){this.visibilityRatio=a;presence.doSync();},_getCookieData:function(){var a={};for(var c in chatDisplay.tabs)if(this.availableList[c])a[c]=this.availableList[c];var b={ac:this.availableCount,ut:parseInt(this.updateTime*.001),ud:parseInt(this.updateDiff),lc:this.listChanged?1:0,cvr:this.visibilityRatio};if(!is_empty(this.updateOverlay))b.uo=this.updateOverlay;if(!is_empty(a))b.al=a;return b;},_computeUpdateTimeDiff:function(){if(!chatOptions.visibility||(presence.poppedOut&&!presence.inPopoutWindow))return Math.round(presence.sitevars.BUDDY_MAX_TIME);var c=presence.sitevars.BUDDY_BASE_TIME;var d=presence.getTime();if(!chatDisplay.everSentMessage)c+=presence.sitevars.BUDDY_COST_NEVER_SENT_MESSAGE;if(!this.listChanged)c+=presence.sitevars.BUDDY_COST_NO_LIST_CHANGE;if(chatTabSlider.numTabs==0)c+=presence.sitevars.BUDDY_COST_NO_CHAT_TABS;var b=(d-chatDisplay.chatActivityTime)/60000;if(b>presence.sitevars.BUDDY_MAX_ACTIVITY_MINS)b=presence.sitevars.BUDDY_MAX_ACTIVITY_MINS;c+=(presence.sitevars.BUDDY_COST_CHAT_ACTIVITY/presence.sitevars.BUDDY_MAX_ACTIVITY_MINS)*b;if(!presence.poppedOut){var e=(d-presence.pageLoadTime)/60000;if(e<b){if(e>presence.BUDDY_MAX_ACTIVITY_MINS)e=presence.BUDDY_MAX_ACTIVITY_MINS;c+=(presence.sitevars.BUDDY_COST_PAGE_ACTIVITY/presence.sitevars.BUDDY_MAX_ACTIVITY_MINS)*e;}if(!this.buddyListOpen){var a=(d-this.buddyViewTime)/60000;if(a>presence.sitevars.BUDDY_MAX_ACTIVITY_MINS)a=presence.sitevars.BUDDY_MAX_ACTIVITY_MINS;c+=(presence.sitevars.BUDDY_COST_VIEW_ACTIVITY/presence.sitevars.BUDDY_MAX_ACTIVITY_MINS)*a;}}if(!c||c>presence.sitevars.BUDDY_MAX_TIME)c=presence.sitevars.BUDDY_MAX_TIME;return Math.round(c);},_checkUpdater:function(c,a,b){this.updateDiff=this._computeUpdateTimeDiff();if(b||(chatOptions.visibility&&!this.stopUpdates&&(c-this.updateTime)>this.updateDiff*1000)){a.popped_out=presence.poppedOut;a.available_list=this.haveFullList?this.availableList:{};a.force_render=this.shouldRender;return true;}},_forceUpdate:function(a){this.shouldRender=true;var b=a?undefined:[ChatBuddyList.UPDATER_NAME];presenceUpdater.forceUpdate(b);},updateUserInfos:function(a){copy_properties(ChatUserInfos,a);},_collapseItem:function(f,a,g,c){if(this.flMode&&c){var d=[c];}else var d=this._getUserFlids(f,a);for(var e=0;e<d.length;e++){var c=d[e];var b=ge(this._getBuddyListItemId(f,c));if(b){b.id=this._getBuddyListWasItemId(f,c);if(g)animation(b).to('height','0px').duration(this.expandAnimDuration).go();this._removeSortable(f,d[e]);}}},_expandItem:function(d,c,h,e,i,j,k){var b=ge(this._getBuddyListItemId(d,c));if(!b){var b=HTML(this._renderItem(d,c,e)).getRootNode();}else if(e)CSS.addClass(b,'idle');var f=(this.isCompactDisplay?this.compactItemHeight:this.itemHeight);var g=this._getFlOpts(c);if(!g.fullDisplay)f=this.compactItemHeight;if(!i){b.style.height=f+'px';DOM.insertAfter(h,b);}else{b.style.height='0px';DOM.insertAfter(h,b);var a=animation(b);if(j)a.duration(this.expandAnimDuration+500).checkpoint();a.from('height','0').to('height',f+'px').duration(this.expandAnimDuration);if(k===undefined)k=!e;if(k){b.style.backgroundColor=this.highlightColor;a.checkpoint().duration(3000).checkpoint().to('backgroundColor',this.backgroundColor).duration(500);}a.go();}this._addSortable(d,c);return b;},_clearWasAvailableItems:function(g,h,b){if(!this.rendered)return;for(var d=0;d<g.length;d++){var e=g[d];if(h[e]){if(this.flMode&&b){var c=[b];}else var c=this._getUserFlids(e,h[e]);for(var f=0;f<c.length;f++){var a=ge(this._getBuddyListWasItemId(e,c[f]));if(a){DOM.remove(a);delete a;}}}}this._showBuddyListEmptyItem();},_showBuddyListEmptyItem:function(){var a=ge(this._getBuddyListEmptyItemId());if(a)CSS.conditionClass(a,'hide_empty_item',this.availableCount!=0);},_hideBuddyListEmptyItem:function(){var a=ge(this._getBuddyListEmptyItemId());if(a)CSS.addClass(a,'hide_empty_item');},_updateAvailableListWithDiff:function(x,zf,j){if(this.stopUpdates)return;var r,t;var zc=false;var zg={};var zh={};var i=(j!=null);this._pruneUsersWithoutDisplayInfo(x);for(var q=0;q<zf.length;q++){var ze=zf[q];if(this.availableList[ze]){zc=true;zg[zf[q]]=this.availableList[ze];if(j&&this.flMode&&this.availableList[ze].fl.length>1){this.availableList[ze].fl.remove(j);zh[ze]=1;continue;}delete this.availableList[ze];}}this._hideBuddyListEmptyItem();var w=keys(x);var zb=!j&&!this.showingError&&!presence.isSafari2&&(zf.length+w.length<this.maxItemsToAnimate);if(this.rendered){for(var q=0;q<zf.length;q++)if(zg[zf[q]])this._collapseItem(zf[q],zg[zf[q]],zb,j);var c=zb?this.expandAnimDuration:0;setTimeout(this._clearWasAvailableItems.bind(this,zf,zg,j),c);}var b=this.sortedList;if(this.haveFullList)this.sortedList=[];this._sort(w,x);var v=w.shift();var a=b.shift();var d=this._compareFunction.bind(this,null);var e={},za={},y={},o={},p={};var n=[];if(this.shouldRender){n=this._getGlobalFlids();for(var q=0;q<n.length;q++){var j=n[q];e[j]=y[j]=this._getAvailableMarkerId(j);za[j]=this._getIdleMarkerId(j);o[j]=p[j]=false;}}var u=false;var k=function(zj,zi,zk){var zl=this._getBuddyListItemId(zj,zi);if(zk){za[zi]=zl;}else y[zi]=zl;o[zi]=o[zi]||zk;p[zi]=p[zi]||!zk;};var l=k.bind(this);while(true){if(a&&zg[a]&&!zh[a]){a=b.shift();continue;}if(a&&v){if(a==v){a=b.shift();continue;}if(d(a,v,this.availableList[a].i,x[v].i)<0){r=a;}else r=v;}else if(a){r=a;}else if(v){r=v;}else break;if(r==a){a=b.shift();t=this.availableList[r].i;if(this.shouldRender){var m=this._getUserFlids(r);for(var q=0;q<m.length;q++)l(r,m[q],t);}}else{v=w.shift();if(this.shouldRender&&this.availableList[r]){var zd=this._getUserFlids(r,this.availableList[r],i);for(var q=0;q<zd.length;q++){var j=zd[q];var h=ge(this._getBuddyListItemId(r,j));if(h){this._removeSortable(r,j);DOM.remove(h);}}}this.availableList[r]=x[r];if(this.shouldRender){t=x[r].i;var m=this._getUserFlids(r,null,i);for(var q=0;q<m.length;q++){var j=m[q];var z=t?ge(za[j]):ge(y[j]);if(!z)z=ge(e[j]);this._expandItem(r,j,z,t,zb,zc);u=true;l(r,j,t);}}}if(this.haveFullList)this.sortedList.push(r);}if(this.shouldRender){for(var q=0;q<n.length;q++){var j=n[q];var s=ge(this._getIdleMarkerId(j));if(s)if(o[j]&&p[j]){CSS.removeClass(s,'hide_idle_marker');}else CSS.addClass(s,'hide_idle_marker');}var f=0;if(zb){var g=u;if(g)f+=this.expandAnimDuration;if(zc){f+=this.expandAnimDuration;if(g)f+=500;}}setTimeout(this.resizeTab.bind(this),f);this._resetFlidClasses();}this._availableListChanged(u);},_sort:function(c,a){a=a||this.availableList;var b=this._compareFunction.bind(this,a);c.sort(b);return c;},_compareFunction:function(a,b,e,c,f){if(typeof c=='undefined')c=a[b].i;if(typeof f=='undefined')f=a[e].i;if(c^f)return c?1:-1;var d=ChatUserInfos[b].name.toLowerCase();var g=ChatUserInfos[e].name.toLowerCase();return (d<g)?-1:1;},_availableListChanged:function(b){if(this.haveFullList)this.availableCount=count(this.availableList);for(var a in this.availableList)this.availableList[a].i=this.availableList[a].i?1:0;if(this.rendered)presenceCookieManager.store();presence.contentChanged(this.contentID);if(!b)this.resizeTab();this._updateCount();Arbiter.inform(ChatBuddyList.AVAILABILITY_CHANGED,{sender:this,justCameOnline:this.justCameOnline});this.justCameOnline=false;},_onUpdaterResponse:function(a,g){if(this.shouldRender&&!a.forcedRender)return;this.updateTime=g;if(!chatOptions.visibility||this.stopUpdates)return;var c=this.haveFullList;var b=this._flChanged(a.flMode,a.flData);var f=is_empty(a.nowAvailableList);this.numRequestFailures=0;this.errorMode=false;this._hideError();this.listChanged=a.listChanged;this.updateUserInfos(a.userInfos);if(!((c&&b)||f)){this.flMode=a.flMode;this.flData=a.flData;}if(this.shouldRender){this.haveFullList=true;if(!this.rendered)this._firstRender();}else{this.availableCount=a.availableCount;this._updateCount();}if(!c||a.wasAvailableIDs.length||!f){for(var e in this.updateOverlay)if(g<this.updateOverlay[e].exp){if(c||!this.availableList[e]){delete a.nowAvailableList[e];}else a.nowAvailableList[e]=this.availableList[e];for(var d=0;d<a.wasAvailableIDs.length;d++)if(e==a.wasAvailableIDs[d]){a.wasAvailableIDs.splice(d,1);break;}}else delete this.updateOverlay[e];if(c){if(b&&!f)a.nowAvailableList=this._massageNowAvailableList(a.nowAvailableList,a.flMode,a.flData);this._updateAvailableListWithDiff(a.nowAvailableList,a.wasAvailableIDs);if(b)this._onFlChange(a.flMode,a.flData);}else{this.availableList=a.nowAvailableList;this._availableListChanged(true);if(this.shouldRender)this._render();}}else{this._availableListChanged.bind(this).defer();if(b&&f)this._onFlChange(a.flMode,a.flData);}},_onUpdaterError:function(a){this.numRequestFailures++;if(this.numRequestFailures>1){this.updateTime=presence.getTime();this.availableCount=0;this._updateCount();this._updateAvailableListWithDiff({},keys(this.availableList));this._showLoadError();}},itemOnClick:function(c,b){var a;if((a=ge(this._getBuddyListItemId(c,b)))&&a.activeDrag)return;presence.pauseSync();chatDisplay.focusTab(c);if(!this.isSticky())this.closeTab();if(this.typeahead)this.typeahead.resetSearch(true);Arbiter.inform(ChatBuddyList.BUDDY_CLICKED,{flid:b,id:c});presence.resumeSync();},_renderItem:function(d,b,e){var l=ChatUserInfos[d];var g=l.name;var k=l.thumbSrc;var h;if(g.length>this.maxNameLen){h=g.substring(0,this.maxNameLen-2)+'...';}else h=g;var a='';if(e)a=_tx("Idle");if(b){var i=sprintf('buddyList.itemOnClick(%d, \'%s\')',d,b);}else var i=sprintf('buddyList.itemOnClick(%d)',d);var f=['<a href="#" class="clearfix friend',(e?' idle':''),'" title="',a,'"','onclick="',i,';return false;" id="',this._getBuddyListItemId(d,b),'">'];var c=!this.isCompactDisplay;var j=this._getFlOpts(b);c&=j.fullDisplay;if(c)f=f.concat('<img src="',k,'" width="22px" height="22px" />');f=f.concat('<span id="',this._getBuddyListItemNameId(d,b),'">',htmlize(h),'</span>','</a>');return f.join('');},_groupAvailableListByFl:function(e,a){if(!this.flMode||!this.flData)return null;e=e||false;a=a||false;var h={};for(var b in this.flData)h[b]=[];if(a)return h;var c=function(l){var k=this.availableList[l].fl;if(k)for(var m=0;m<k.length;++m){var j=k[m];h[j].push(l);}};var d=c.bind(this);if(e){var i=this._getSortedList();for(var f=0;f<i.length;f++)d(i[f]);}else for(var g in this.availableList)d(g);return h;},_listNameInUse:function(b){for(var a in this.flData)if(this.flData[a].n==b)return true;return false;},keyPressNewListInput:function(b){if(Event.getKeyCode(b)==KEYS.RETURN){var b=$E(b);var c=b.getTarget().value;if(this._listNameInUse(c)){new ErrorDialog().showError(_tx("An error occurred."),_tx("You cannot have two lists with the same name. Please create a unique name for this list."));return;}var a={create:c};this._saveBuddyListSetting(a,function(){for(var d in this.flData)if(this.flData[d].n==c){Vector2.scrollIntoView($(this._getFriendListId(d)));break;}}.bind(this));return b.kill();}},handleFlInChat:function(b,a){buddyListDisplay.closeOpenFlyout();if(b){this._unHideFriendListFromChat(a);}else this._hideFriendListFromChat(a);},_unHideFriendListFromChat:function(b){var d=this._getFriendListsInChat().length==0;var c=[b];var a={unhide_from_chat:1,flids:c};this.flData[b].h=0;this._saveBuddyListSetting(a,function(){this._showEmptyListMomentarily(b);Vector2.scrollIntoView($(this._getFriendListId(b)));}.bind(this));if(d){this._onFlChange(true,this.flData);}else this._addFlidsToDOM(c);},_hideFriendListFromChat:function(b){var d=this._getFriendListsInChat().length==1;var c=[b];var a={hide_from_chat:1,flids:c};this.flData[b].h=1;this._saveBuddyListSetting(a);if(d){this._onFlChange(false,this.flData);}else this._removeFlidsFromBuddyList(c);},_friendListHandleSwitchThrown:function(b){var a=this.flData[b].o;if(a){this._goOfflineToLists([b]);}else this._goOnlineToLists([b]);},_friendListHandleSwitchMouseDown:function(b){var a=Event.listen(document,'mouseup',function(){a.remove();this._friendListHandleSwitchThrown(b);}.bind(this));},_friendListHandleMouseOver:function(a){if(this.reorderingLists)return;CSS.addClass($(this._getFriendListId(a)),'hover');},_friendListHandleMouseOut:function(a){CSS.removeClass($(this._getFriendListId(a)),'hover');},_saveBuddyListSetting:function(b,a){b.user=this.user;a=a||bagofholding;new AsyncRequest().setData(b).setURI('/ajax/chat/buddy_list_settings.php').setHandler(this._onBuddyListSettingSave.bind(this,a)).setFinallyHandler(function(){buddyListDisplay.closeOpenFlyout();}).send();},_goOnlineToLists:function(b,c){c=c||false;var a={online_to_list:1,flids:b,read_only:c};this._handleFlVisibilityChange(b,1);this._saveBuddyListSetting(a);},_handleFlVisibilityChange:function(d,f,a){for(var e=0;e<d.length;e++){var c=d[e];var b=ge(this._getFriendListId(c));if(!b)continue;this.flData[c].o=f;if(f){CSS.addClass(b,'online');CSS.removeClass(b,'offline');if(c==this.otherFriendsFlid)this._showEmptyListMomentarily(c);}else{CSS.addClass(b,'offline');CSS.removeClass(b,'online');}var g=DOM.find(b,'div.titletip strong');DOM.setText(g,this._getFriendListTooltipText(c));a&&a(c);}},_showEmptyListMomentarily:function(b){this.shownEmptyFlids=this.shownEmptyFlids||{};this.shownEmptyFlids[b]=1;var a=ge(this._getFriendListId(b));if(a)CSS.addClass(a,'show_empty_list');(function(){delete this.shownEmptyFlids[b];var c=ge(this._getFriendListId(b));if(c)CSS.removeClass(c,'show_empty_list');}).bind(this).defer(8000);},_goOfflineToLists:function(b,d){d=d||false;var c=this._groupAvailableListByFl();this._handleFlVisibilityChange(b,0,function(e){var f=c[e];this._removeFromBuddyList(f,e);}.bind(this));if(!d){var a={offline_to_list:1,flids:b};this._saveBuddyListSetting(a);}},_removeFlidsFromBuddyList:function(c,d){d=d||this._groupAvailableListByFl(true);if(!d)return;var i={};for(var e=0;e<c.length;e++){var b=c[e];var g=d[b];if(!g)continue;for(var h=0;h<g.length;h++){var f=g[h];var a={};a.i=this.availableList[f].i;a.fl=this.availableList[f].fl.clone();if(this.flMode){a.fl.remove(b);if(a.fl.length==0)a.fl.push(this.otherFriendsFlid);}else delete a.fl;i[f]=a;}}if(!is_empty(i))this._updateAvailableListWithDiff(i,[]);this._removeFlidsFromDOM(c);},_onBuddyListSettingSave:function(b,a){var e=a.getPayload();if(e){if(e.availableList){this.updateUserInfos(e.userInfos);var d;if(e.flids&&e.flids.length==1)d=e.flids[0];this._updateAvailableListWithDiff(e.availableList,[],d);}if(e.flData){var c;if(typeof e.flMode!='undefined'){c=e.flMode;}else c=true;this._onFlChange(c,e.flData);this._resetFlidClasses();}b&&b();}},_flManagerHandler:function(b,a){},_resetFlidClasses:function(){if(!this.flMode)return;var c=this._groupAvailableListByFl();for(var b in this.flData){var a=ge(this._getFriendListId(b));if(a)CSS.setClass(a,this._getFriendListItemClasses(b,c));}},_getFriendListItemClasses:function(b,e){var d=this.flData[b].o;var c=this.flData[b].h;var a=['friend_list'];if(d){a.push('online');}else a.push('offline');if(!c&&this.shownEmptyFlids&&this.shownEmptyFlids[b])a.push('show_empty_list');if(is_empty(e[b]))if(this.availableCount!=0&&(this.flData[b].c==0||b==this.otherFriendsFlid)){a.push('empty_friend_list');}else if(d)a.push('hide_friend_list');if(b==this.otherFriendsFlid){a.push('compact_friend_list');a.push('other_friends_list');}if(this.reorderingLists&&(b==this.otherFriendsFlid||b==this.botsFlid))a.push('suppress');return a.join(' ');},_renderFriendListHeader:function(c){var b=this.flData[c].n;var e=this.flData[c].o;var a='';var f=typeof this.flData[c].s!='undefined';if(!f&&c!=this.otherFriendsFlid)var a='<a href="/friends/ajax/edit_list.php?list_id='+c+'" '+'rel="dialog-post">'+_tx("edit")+'</a>';var d=['<div class="friendlist_name">','<span class="title"><a href="#">',htmlize(b),'</a></span>','<span class="edit_link">',a,'</span>','</div>'];if(!f)d.push('<div class="switch"><a class="online_status" ','>','<div class="titletip"><strong>',this._getFriendListTooltipText(c),'</strong></div>','</a>','</div>');return d.join('');},_getFriendListTooltipText:function(a){return this.flData[a].o?_tx("Go Offline"):_tx("Go Online");},registerExternalFriendList:function(b){if(!this.rendered)this._firstRender();var a='xfl_'+this.externalFlids.length;this.externalFlids.push(a);this.flOpts[a]=b;return a;},_renderFriendListContent:function(a,i){var l;var d=this.flMode&&a;if(d){l=['<div id="',this._getFriendListContainerId(a),'"','class="friend_list_container">'];}else l=[];l.push('<div id="',this._getAvailableMarkerId(a),'" class="suppress"></div>');var g=[];var b=false,c=false;for(var k=0;k<i.length;k++){var e=i[k];var f=this.availableList[e].i;var j=[this._renderItem(e,a,f)];if(f){b=true;g=g.concat(j);}else{c=true;l=l.concat(j);}}var h=(b&&c)?'':' hide_idle_marker';l.push('<div id="',this._getIdleMarkerId(a),'" class="subheader',h,'"></div>');l=l.concat(g);if(d)l.push('</div>');return l.join('');},_addFriendListListeners:function(c){if(!this.flMode)return;c=c||this._getRenderedFriendLists();for(var d=0;d<c.length;d++){var b=c[d];if(typeof this.flData[b].s!='undefined')continue;var a=$(this._getFriendListId(b));Event.listen(a,'mouseover',this._friendListHandleMouseOver.bind(this,b));Event.listen(a,'mouseout',this._friendListHandleMouseOut.bind(this,b));var e=DOM.find(a,'a.online_status');Event.listen(e,'mousedown',this._friendListHandleSwitchMouseDown.bind(this,b));}},_renderBuddyContent:function(){var a=(this.availableCount?'hide_empty_item':'');var g=['<div id="buddy_list_all" class="subgroup">',this.renderEmptySearch(),'<div id="buddy_list_parent" class="list_select">','<div id="',this._getBuddyListEmptyItemId(),'" class="info_text ',a,'">',_tx("No one is available to chat."),'</div>'];var c;var d={};if(this.flMode){c=keys(this.flData);d=this._groupAvailableListByFl(true);}else c=[null];for(var e=0;e<c.length;++e){var b=c[e];var f=[];if(this.flMode&&b){if(this.flData[b].h)continue;g.push('<div id="',this._getFriendListId(b),'"','class="',this._getFriendListItemClasses(b,d),'">',this._renderFriendListHeader(b));f=d[b];}else f=this._getSortedList();g.push(this._renderFriendListContent(b,f));if(this.flMode&&b)g.push('</div>');}g.concat(['</div>','</div>']);return g.join('');},renderEmptySearch:function(a){var b='<div id="'+this._getEmptySearchId(a)+'" class="info_text" style="display:none">'+_tx("Could not find that friend online.")+'</div>';return b;},_render:function(){this._getSortedList();CSS.conditionClass(this.contentDiv,'compact',this.isCompactDisplay);var a=this._renderBuddyContent();if(this.rendered)CSS.addClass(this.contentDiv,'hidden');this.contentDiv.innerHTML=a;presence.contentChanged(this.contentID);if(this.rendered){CSS.addClass(this.wrapperDiv,'presence_menu_offscreen');this._hideError();CSS.removeClass(this.contentDiv,'hidden');this.resizeTab();CSS.removeClass(this.wrapperDiv,'presence_menu_offscreen');this._initDragging();this._addFriendListListeners();}if(this.errorMode)this._showLoadError();if(this.shouldShowLoading){this._showLoading();this.shouldShowLoading=false;}},_firstRender:function(){this._render();this.rendered=true;this.loadTypeahead();},updateItemDisplay:function(d){var a=this.availableList[d];if(!a)return;var f=this._getUserFlids(d);for(var c=0;c<f.length;c++){var b=f[c];var e=ge(this._getBuddyListItemId(d,b));if(!e)return;e=HTML(this._renderItem(d,b,a.i)).getRootNode();}},_showLoadError:function(){this._showError(_tx("Could not load available friends."));},_showLoading:function(){this._showError(_tx("Loading..."));},_hideError:function(){this.showingError=false;CSS.removeClass(this.wrapperDiv,'error');},_showError:function(a){this.showingError=true;set_inner_html(this.buddyListError,a);CSS.addClass(this.wrapperDiv,'error');},isSticky:function(){return chatOptions.getSetting('sticky_buddylist');},enterReorderingFlMode:function(){if(this.reorderingLists)return;this.reorderingLists=true;CSS.addClass(this.wrapperDiv,'reorder_fl');var a=this._getRenderedFriendLists();this.flSortableGroup=new SortableGroup();for(var c=0;c<a.length;c++){var b=a[c];if(b==this.otherFriendsFlid||b==this.botsFlid){CSS.addClass(this._getFriendListId(b),'suppress');}else this._addFlSortable(b);}var d=$N('div',{id:'reorder_fl_alert'},[$N('span',{className:'helper_text'},_tx("Drag lists to re-order.")),$N('input',{type:'button',className:'inputbutton',value:_tx("Done Re-Ordering"),onclick:this.exitReorderingFlMode.bind(this)})]);DOM.insertBefore(d,this.contentDiv);this.freezeTabSize(false);},exitReorderingFlMode:function(){if(!this.reorderingLists)return;this._reorderFlids();DOM.remove($('reorder_fl_alert'));CSS.removeClass(this.wrapperDiv,'reorder_fl');var a=this._getRenderedFriendLists();for(var c=0;c<a.length;c++){var b=a[c];if(b==this.otherFriendsFlid||b==this.botsFlid){CSS.removeClass(this._getFriendListId(b),'suppress');}else this._removeFlSortable(b);}this.reorderingLists=false;this.unfreezeTabSize.bind(this).defer(50);this.flSortableGroup.destroy();this.flSortableGroup=null;},_addFlSortable:function(a){if(this.flSortableGroup!=null){this.flSortableGroup.addSortable(a,$(this._getFriendListId(a)));animation($(this._getFriendListContainerId(a))).to('height','0px').to('opacity',0).from(1).blind().hide().ease(animation.ease.end).duration(300).go();}},_removeFlSortable:function(b){if(this.flSortableGroup!=null){this.flSortableGroup.removeSortable(b);var a;if(a=ge(this._getFriendListContainerId(b)))animation(a).to('height','auto').from('0px').to('opacity',1).from(0).blind().show().ease(animation.ease.end).duration(300).go();}},_reorderFlids:function(){var a={reorder:1,flids:this.flSortableGroup.getOrder()};this._saveBuddyListSetting(a);},_getDragKey:function(b,a){return b+'_'+a;},_initDragging:function(){if(!this.flMode)return;var c=this._groupAvailableListByFl();this.sortables={};var b=this._getRenderedFriendLists();for(var d=0;d<b.length;d++){var a=b[d];var e=c[a];this._initFlidSortable(a,e);}},_initFlidSortable:function(c,d){if(!c||!this.flMode)return;if(this.flData[c].s)return;var b=head(this.sortables);this.sortables[c]=new SortableGroup();if(b)b.link(this.sortables[c]);var a=$N('div',{id:this._getEmptyListDropZoneId(c),className:'list_drop_zone'},$N('span',{className:'list_drop_zone_inner'},_tx("Drag a friend here to add")));var f=$(this._getFriendListContainerId(c));this.sortables[c].addEmptyMessage(a,f).setBoundingBox(this._getBoundingBox()).setDragOverCallback(this._dragOverHandler.bind(this)).setDropCallback(this._dropHandler.bind(this)).setGrabCallback(this._grabHandler.bind(this));for(var e=0;e<d.length;e++)this._addSortable(d[e],c);},_getBoundingBox:function(){return Rect.newFromVectors(new Vector2(0,0),Vector2.getElementDimensions(this.contentDiv));},_destroyFlidSortable:function(a){if(!a||!this.flMode)return;if(this.sortables&&this.sortables[a]){this.sortables[a].destroy();delete this.sortables[a];}},_addSortable:function(b,a){if(!a||!this.flMode||!this.flData[a])return;if(this.flData[a].s)return;if(!this.sortables[a])return;var c=this._getDragKey(b,a);if(this.sortables[a].keyExists(c))return;this.sortables[a].addSortable(c,ge(this._getBuddyListItemId(b,a)));},_removeSortable:function(b,a,c){if(!a||!this.flMode)return;if(this.sortables[a])this.sortables[a].removeSortable(this._getDragKey(b,c||a));},_dragOverHandler:function(a,b){if(CSS.hasClass(b,'list_drop_zone')){var c=this._extractFlid(b.id);var d=$(this._getFriendListId(c));CSS.addClass(d,'drag_over');}},_grabHandler:function(a){CSS.addClass($('buddy_list_parent'),'drag_active');},_dropHandler:function(e){CSS.removeClass($('buddy_list_parent'),'drag_active');var k=e.split('_');if(k.length!=2)return;var d=k[0];var h=k[1];var c=$(this._getBuddyListItemId(d,h));if(!c)return;var g=this._extractFlid(c.parentNode.id);if(g==h){this._updateUIAfterDragging(d,h,h,c);}else{if(this.flData[h].s||this.flData[g].s){this._updateUIAfterDragging(d,h,h,c);return;}var a=this.availableList[d].fl;var f=false;var i=false;var j=false;if(g==this.otherFriendsFlid){i=true;if(a.length==1){this.availableList[d].fl=[this.otherFriendsFlid];}else{this.availableList[d].fl.remove(h);j=true;DOM.remove(c);Vector2.scrollIntoView(this.getBuddyItem(d));}}else if(a.length==1){this.availableList[d].fl=[g];f=h!=this.otherFriendsFlid;}else{f=true;this.availableList[d].fl.push(g);this.availableList[d].fl.remove(h);}if(j||this._updateUIAfterDragging(d,h,g,c)){var b;if(i){b={remove_fl:true,old_flid:h,drag_uid:d};}else if(f){b={move_fl:true,new_flid:g,old_flid:h,drag_uid:d};}else b={add_fl:1,new_flid:g,drag_uid:d};this._saveBuddyListSetting(b);}}this._resetFlidClasses();},_updateUIAfterDragging:function(c,f,e,a){var b=this._groupAvailableListByFl(true);var h=b[e];var d=h.indexOf(c);var g;if(d==-1){return false;}else if(d==0){g=$(this._getAvailableMarkerId(e));}else g=$(this._getBuddyListItemId(h[d-1],e));(function(){var j,k=false;if(h.length!=1)j=showHight=true;var i=this._expandItem(c,e,g,this.availableList[c].i,j,false,k);if(f!=e){DOM.remove(a);this._removeSortable(c,e,f);}Vector2.scrollIntoView(i);}).bind(this).defer(500);return true;},_getGlobalFlids:function(a){var b=this.flMode&&this.flData?keys(this.flData):[null];return a?b:b.concat(this.externalFlids);},_getUserFlids:function(d,a,b){a=a||this.availableList[d];var c=a.fl?a.fl:[null];if(!b){if(!a.allFlids)a.allFlids=this._addExternalFlids(d,c);c=a.allFlids;}return c;},_addExternalFlids:function(d,b){b=b.concat();for(var c=0;c<this.externalFlids.length;c++){var a=this.externalFlids[c];var e=this._getFlOpts(a);if(!e.excludeIds[d])b.push(a);}return b;},_getFlOpts:function(a){return this.flOpts[a]||ChatBuddyList.DEFAULT_OPTS;},_getAvailableMarkerId:function(a){return this._encodeFlid('buddy_list_avail_marker',a);},_getIdleMarkerId:function(a){return this._encodeFlid('buddy_list_idle_marker',a);},_getEmptyListDropZoneId:function(a){return this._encodeFlid('buddy_list_drop_zone',a);},_getBuddyListItemId:function(b,a){return this._encodeFlid('buddy_list_item_'+b,a);},_getBuddyListItemNameId:function(b,a){return this._encodeFlid('buddy_list_item_name_'+b,a);},_getBuddyListWasItemId:function(b,a){return this._encodeFlid('buddy_list_was_item_'+b,a);},_getEmptySearchId:function(a){return this._encodeFlid('buddy_list_empty_search',a);},_getBuddyListEmptyItemId:function(){return 'buddy_list_empty_item';},_encodeFlid:function(a,b){return b?(b+'_'+a):a;},_getFriendListId:function(a){return this._encodeFlid('friend_list_item',a);},_extractFlid:function(a){return a.split('_').shift();},_getFriendListContainerId:function(a){return this._encodeFlid('friend_list_container',a);},debugPrintUpdateOverlay:function(){var b=this.updateOverlay;for(var a in b);}};
function ChatBuddyListDisplay(a){this.openFlyout=null;this.openControl=null;this.panelID=a;if(presence.inPopoutWindow){this._init();}else this.arbiterInit=Arbiter.subscribe(PresenceMessage.TAB_OPENED,this._onTabOpen.bind(this));}ChatBuddyListDisplay.prototype={_onTabOpen:function(c,a){var b=a.tabID;if(b&&b=='buddy_list_tab'){Arbiter.unsubscribe(this.arbiterInit);this._init();}},_init:function(){this.buddyListPanel=$(this.panelID,true);var a=this._clickControlPanel.bind(this,'buddy_list_panel_lists_control','buddy_list_panel_lists_flyout',this._getListsFlyoutContent.bind(this));Event.listen(DOM.find(this.buddyListPanel,'#buddy_list_panel_lists_control a'),'click',a);var b=this._clickControlPanel.bind(this,'buddy_list_panel_settings_control','buddy_list_panel_settings_flyout',this._getChatSettingsNodes.bind(this));Event.listen(DOM.find(this.buddyListPanel,'#buddy_list_panel_settings_control a'),'click',b);},_clickVisibilityToggle:function(){chatOptions.toggleVisibility();this.closeOpenFlyout();},_clickReorderLists:function(){buddyList.enterReorderingFlMode();this.closeOpenFlyout();},_clickControlPanel:function(a,b,c){if(this.openFlyout){if(this.openFlyout==b){this.closeOpenFlyout();}else{this.closeOpenFlyout();this._openFlyout(a,b,c());}}else this._openFlyout(a,b,c());return false;},_openFlyout:function(c,e,a){DOM.setContent($(e),a);CSS.removeClass(e,'hidden_elem');CSS.addClass(c,'flyout_open');if(!presence.poppedOut){var d=Vector2.getElementDimensions($(e)).y;var b=Vector2.getElementDimensions(buddyList.getContentWrapper()).y;if(d>b)CSS.addClass(e,'flyout_reversed');}this.openFlyout=e;this.openControl=c;},isFlyoutOpen:function(){return this.openFlyout;},closeOpenFlyout:function(){if(!this.openFlyout)return;CSS.addClass(this.openFlyout,'hidden_elem');CSS.removeClass(this.openFlyout,'flyout_reversed');CSS.removeClass(this.openControl,'flyout_open');this.openFlyout=null;this.openControl=null;},_getListsFlyoutContent:function(){var f=$N('input',{className:'inputtext',type:'text'});f.listen('keypress',buddyList.keyPressNewListInput.bind(buddyList));new TextInputControl(f).setPlaceholderText(_tx("Type a list name"));var e=$N('div',{className:'new_list'},[$N('span',{},_tx("Create a new list:")),f]);var d=$N('div',{className:'text'},_tx("Display these lists in Chat:"));var b=buddyList.getFriendLists();var a=new UISelectList();a.setCallback(buddyList.handleFlInChat.bind(buddyList));for(var c in b)a.addItem(b[c].n,!b[c].h,c);return [d,a.getElement(),e];},_renderListSettingToggle:function(c,a,b){return this._renderToggle('list_online_'+c,a,b,'list_online_checkbox_'+c,function(d,e){buddyList.handleFlInChat(c,d);});},_renderChatSettingToggle:function(b,c,a){return this._renderToggle('chat_setting_'+b,c,a,'chat_setting_checkbox_'+b,function(d,e){this.sendSettingChange(b,d.checked);}.bind(this));},_renderToggle:function(d,c,e,b,g){var a=$N('input',{type:'checkbox',id:b,name:b});a.checked=c;a.defaultChecked=c;a.listen('click',g.bind(this,a));var f=$N('label',{},e);f.setAttribute('for',b);return $N('div',{className:'chat_setting clearfix',id:d},[$N('div',{className:'input_box'},[$N('span',{className:'show_loading'},$N('img',{src:'/images/loaders/indicator_blue_small.gif'})),$N('span',{className:'hide_loading'},a)]),f]);},_getChatSettingsNodes:function(){var c=[];if(this.buddyListPanel){var d=$N('a',{className:'go_offline_control'},[$N('div',{className:'menu_icon'}),$N('span',{},_tx("Go Offline"))]);d.listen('click',this._clickVisibilityToggle.bind(this));var e=$N('div',{className:'options_actions'},d);if(buddyList._getFriendListsInChat().length>1){var g=$N('a',{className:'list_reorder_control'},[$N('div',{className:'menu_icon'}),$N('span',{},_tx("Re-order Lists"))]);g.listen('click',this._clickReorderLists.bind(this));e.appendChild(g);}var f=$N('a',{className:'list_popout_control'},[$N('div',{className:'menu_icon'}),$N('span',{},(presence.poppedOut?_tx("Pop in Chat"):_tx("Pop out Chat")))]);f.listen('click',presence.popout.bind(presence));e.appendChild(f);c.push(e);c.push($N('hr',{className:'menu_divider'}));}var b=[{name:'sound',label:_tx("Play Sound for New Messages")},{name:'sticky_buddylist',label:_tx("Keep Online Friends Window Open")},{name:'compact_buddylist',label:_tx("Show Only Names in Online Friends")}];for(var a=0;a<b.length;a++)c.push(this._renderChatSettingToggle(b[a].name,chatOptions.getSetting(b[a].name),b[a].label));return c;},_onSettingChangeResponse:function(a,c,b){chatOptions.setSetting(a,c);CSS.removeClass($('chat_setting_'+a),'chat_setting_loading');presence.doSync();},_onSettingChangeError:function(a,b){presence.showAsyncError(b,_tx("Couldn't change that setting"));CSS.removeClass($('chat_setting_'+a),'chat_setting_loading');},sendSettingChange:function(b,c){CSS.addClass($('chat_setting_'+b),'chat_setting_loading');var a={};a[b]=c;new AsyncRequest().setHandler(this._onSettingChangeResponse.bind(this,b,c)).setErrorHandler(this._onSettingChangeError.bind(this,b)).setTransportErrorHandler(this._onSettingChangeError.bind(this,b)).setData(a).setURI(chatDisplay.settingsURL).send();}};
function ExternalFriendList(b,a,c,d){this.elemId=b;this.bodyElemId=b+'_body';this.statusElemId=b+'_status';this.condensed=a;this.excludeIds=c;this.itemOnClick=d;this.rendered=false;}ExternalFriendList.prototype={render:function(b,a){if(this.rendered)return;Arbiter.subscribe([ChatBuddyList.BUDDY_LIST_INITIALIZED],this._onInit.bind(this));},_onInit:function(){if(chatOptions.visibility){if(buddyList.haveFullList){this._render();}else{Arbiter.subscribe([ChatBuddyList.AVAILABILITY_CHANGED],this._render.bind(this));buddyList._forceUpdate();}this.onShow();}else this.onHide();Arbiter.subscribe(PresenceMessage.SHUTDOWN,this.onHide.bind(this));Arbiter.subscribe(PresenceMessage.RESTARTED,this.onShow.bind(this));Arbiter.subscribe(ChatOptions.VISIBILITY_CHANGED,this._handleVisibility.bind(this));},_render:function(){if(this.rendered)return;var d={fullDisplay:!this.condensed,excludeIds:this.excludeIds};Arbiter.subscribe(ChatBuddyList.BUDDY_CLICKED,this._handleOnClick.bind(this));var a=this.flid=buddyList.registerExternalFriendList(d);var c=keys(buddyList.availableList);if(count(this.excludeIds))c=c.filter((function(e){return (this.excludeIds[e]!=1);}).bind(this));c=buddyList._sort(c,null);var b=buddyList.renderEmptySearch(a)+'<ul class="list_select">'+'<li id="'+buddyList._getFriendListId(a)+'">'+buddyList._renderFriendListContent(a,c,true)+'</li>'+'</ul>';this.typeahead=new ChatBuddyListTypeahead($(this.elemId+'_buddy_list_typeahead_input'),$(this.elemId+'_buddy_list_typeahead'),a,this.excludeIds);$(this.bodyElemId).setContent(HTML(b));this.rendered=true;},_handleOnClick:function(b,a){if(a.flid==this.flid)this.itemOnClick(a.id);},_handleVisibility:function(){chatOptions.visibility?this.onShow():this.onHide();},onHide:function(){DOM.setContent($(this.statusElemId),_tx("You are Offline."));CSS.addClass($(this.bodyElemId),"buddy_list_hidden");CSS.removeClass($(this.statusElemId),"buddy_list_hidden");},onShow:function(){CSS.removeClass($(this.bodyElemId),"buddy_list_hidden");CSS.addClass($(this.statusElemId),"buddy_list_hidden");}};function ChatInviteFriendList(b,a,f,c){var e=function(g){var h=$(chatDisplay.tabs[g].getInputElemId());h.value=f;h.focus();};var d=new ExternalFriendList(b,a,c,e);d.render();}
function ChatOptions(b,a){this.visibility=b;this.settings=a;this._init();}copy_properties(ChatOptions,{VISIBILITY_CHANGED:'chat/visibility-changed'});ChatOptions.prototype={_init:function(){presence.registerStateStorer(this._storeState.bind(this));presence.registerStateLoader(this._loadState.bind(this));},_storeState:function(a){a.vis=this.visibility;a.bls=this.getSetting('sticky_buddylist');a.blc=this.getSetting('compact_buddylist');a.snd=this.getSetting('sound');return a;},_loadState:function(a){if(a.vis!=this.visibility)this.setVisibility(a.vis);this.setSetting('sticky_buddylist',a.bls);this.setSetting('compact_buddylist',a.blc);this.setSetting('sound',a.snd);},setVisibility:function(a){if(a==this.visibility)return;this.visibility=a;if(a){channelManager.isActionRequest=true;channelManager.rebuild(ChannelRebuildReasons.UIRestart);}else channelManager.setReady(false);Arbiter.inform(ChatOptions.VISIBILITY_CHANGED,{sender:this});},_onVisibilityResponse:function(a,b){presence.pauseSync();this.setVisibility(a);if(!presence.inPopoutWindow&&!a)chatDisplay.unfocus();presence.resumeSync();if(presence.poppedOut)presence.popout();},_onVisibilityError:function(b){var a=_tx("Chat");presence.showAsyncError(b,_tx("Couldn't set {Chat} availability",{Chat:a}));},toggleVisibility:function(){this.sendVisibility(!this.visibility);},sendVisibility:function(a){if(this.visibility==a)return;this.visibilityAsync=new AsyncRequest().setHandler(this._onVisibilityResponse.bind(this,a)).setErrorHandler(this._onVisibilityError.bind(this)).setTransportErrorHandler(this._onVisibilityError.bind(this)).setData({visibility:a}).setURI(chatDisplay.settingsURL).send();},getSetting:function(a){return this.settings[a];},setSetting:function(a,b){if(this.getSetting(a)==b)return;if(a=='compact_buddylist')buddyList.setCompactDisplay(b);this.settings[a]=b;}};
function ChatTabSlider(){this.handleWidth=141;this.animationTime=210;this._init();}ChatTabSlider.prototype={_init:function(){this.org_s=0;this.numToShow=0;this.numShift=1;this.shiftByNumTabs=false;this.timer=null;this.skipAnimation=false;this.chatWidth=null;this.tabPos={};this.chat=ge('chat');this.chatTabBar=ge('chat_tab_bar');this.nextTab=ge('chat_next_tab');this.prevTab=ge('chat_previous_tab');this.nextCounter=ge('next_count');this.prevCounter=ge('prev_count');this.numNext=0;this.numPrev=0;this.prevTabs={};this.nextTabs={};this.numMissedNextCounter=ge('next_num_missed');this.numMissedPrevCounter=ge('prev_num_missed');presence.registerStateLoader(this._load.bind(this));presence.registerStateStorer(this._store.bind(this));Arbiter.subscribe(PresenceMessage.WINDOW_RESIZED,this._resize.bind(this,false));},load:function(){this._load(presence.state);this._resize(true);},_load:function(a){var b=0;if(a)b=(a.s?a.s:b);this._setPos(b);},_store:function(a){a.s=this._s;return a;},_calculate:function(a){this._setMaxWidth();if(a)this.maxWidth-=16;if(presence.poppedOut){this.numToShow=chatDisplay.numTabs;}else{this.numToShow=parseInt(this.maxWidth/this.handleWidth);this.numToShow=this.numToShow>0?this.numToShow:1;}if(this.shiftByNumTabs)this.numShift=this.numToShow;if(this._s!=null)this._setPos(this._s);},_setMaxWidth:function(){var c=DOMScroll.getScrollRoot().offsetWidth;if(ChatTabSlider.presenceWidthTest)var c=$('presence_ui').offsetWidth;var a=['buddy_list_tab','presence_notifications_tab','presence_applications_tab','icon_garden','bookmarkable_app'];for(var b=0;b<a.length;b++)c-=(ge(a[b])&&$(a[b]).clientWidth!=undefined)?ge(a[b]).clientWidth:0;this.maxWidth=(presence.poppedOut?c-254:c-138);},_setPos:function(a){if(a<0)a=0;this._s=a;this._e=this._s+this.numToShow;},_doSync:function(){var a=(this.org_s!=this._s);this.org_s=0;if(a)presence.doSync();},_build:function(){if(presence.poppedOut)return;var a=(this.numToShow>=chatDisplay.numTabs)?true:false;this.setVisibleTabs(a);if(a){this.resetCounters();}else this.updateCounters();this.updateMissedCount();},_resize:function(a){this.org_s=this._s;this._calculate(a);this._build();this._doSync();if(chatDisplay.lastFocused!=null)this.gotoTab(chatDisplay.lastFocused);},addTab:function(a){this._build();},gotoTab:function(a){if(this.tabPos[a]!=0&&!this.tabPos[a])return;var b=parseInt(this.tabPos[a]);if(!this._inRange(b)){var c=(b-this.numToShow)+1;this._setPos(c);this._build();}},close:function(a){if(this.tabPos[a]!=0&&!this.tabPos[a])return;delete this.tabPos[a];this._setPos(((this.numPrev>0||this.numNext>0)&&this._s>0)?this._s-1:0);this._calculate();this._build();},setVisibleTabs:function(a){var b=0;for(var c in chatDisplay.tabs){this.tabPos[c]=b;if(this._inRange(b,c)||a==true){chatDisplay.tabs[c].show();}else chatDisplay.tabs[c].hide();b++;}},_inRange:function(c,b){var d,a=false;if(c>=this._s){d=true;delete this.prevTabs[b];}else this.prevTabs[b]=b;if(c<this._e){a=true;delete this.nextTabs[b];}else this.nextTabs[b]=b;return (d&&a);},updateMissedCount:function(){var c=0;var b=0;for(var a in this.prevTabs)c+=chatDisplay.tabs[a]?chatDisplay.tabs[a].numMissed:0;this.numMissedPrevCounter.innerHTML=c;this.numMissedPrevCounter.style.display=c>0?'block':'none';for(var a in this.nextTabs)b+=chatDisplay.tabs[a]?chatDisplay.tabs[a].numMissed:0;this.numMissedNextCounter.innerHTML=b;this.numMissedNextCounter.style.display=b>0?'block':'none';},updateCounters:function(){this.numNext=chatDisplay.numTabs-this._e;this.numPrev=this._s;if(this.numNext<=0){this.numNext=0;CSS.addClass(this.nextTab,'disabled');}else CSS.removeClass(this.nextTab,'disabled');if(this.numPrev<=0){this.numPrev=0;CSS.addClass(this.prevTab,'disabled');}else CSS.removeClass(this.prevTab,'disabled');if(this.numPrev>0||this.numNext>0){show('chat_next_tab');show('chat_previous_tab');}else{hide('chat_next_tab');hide('chat_previous_tab');}this.nextCounter.innerHTML=this.numNext;this.prevCounter.innerHTML=this.numPrev;},resetCounters:function(){this._setPos(0);this.updateCounters();},shift:function(a){this.org_s=this._s;chatDisplay.unfocusNoSync();this._shift.bind(this,a).defer();},_shift:function(a){this._setPos(this._s<0?0:this._s+a);this._slide(a);if(this.timer||this.skipAnimation){this._slideReset();this.skipAnimation=true;var b=setTimeout(function(){this.skipAnimation=false;}.bind(this),500);}else this.timer=setTimeout(function(){this._slideReset();}.bind(this),this.animationTime);},_slide:function(a){this._slideSetup(false);this.setVisibleTabs(true);this.slideInc=(a*(this.handleWidth));this.leftPos=-(a)*(this.numNext*(this.slideInc));this.chatTabBar.style.left=this.leftPos+'px';animation(this.chatTabBar).by('left',this.slideInc).duration(this.animationTime-10).go();},_slideSetup:function(a){this.chat.style.position=a?'':'relative';this.chat.style.overflow=a?'visible':'hidden';if(!this.chatWidth)this.chatWidth=this.chatTabBar.clientWidth;if(a)this.chatWidth=null;this.chat.style.width=a?'':this.chatWidth+'px';this.chatTabBar.style.width=a?'':chatDisplay.numTabs*this.handleWidth+'px';this.chatTabBar.style.position=a?'':'absolute';},_slideReset:function(){clearTimeout(this.timer);this.timer=null;this._slideSetup(true);this._build();if(chatDisplay.lastFocused)if(this._inRange(this.tabPos[chatDisplay.lastFocused])){chatDisplay.refocus();}else chatDisplay.lastFocused=null;this._doSync();},next:function(){if(this.numNext<=0)return;this.shift(this.numShift);},prev:function(){if(this.numPrev<=0)return;this.shift(-this.numShift);}};
function CounterDisplay(a,f,g,d,c){copy_properties(this,{_name:a,_valueNode:$(f),_wrapperNode:$(g)||null,_statusClass:c,_rm:new RenderManager(this),_arbiterSubscription:null,_count:0});var b=this._valueNode.firstChild;if(b){var e=parseInt(b.nodeValue,10);if(!isNaN(e))this._count=e;}this._statusNode=d?$(d):null;this._subscribeAll();CounterDisplay.instances.push(this);onunloadRegister(this._destroy.bind(this),true);}copy_properties(CounterDisplay,{EVENT_TYPE_ADJUST:'CounterDisplay/adjust',EVENT_TYPE_UPDATE:'CounterDisplay/update',instances:[],adjustCount:function(a,b){Arbiter.inform(CounterDisplay.EVENT_TYPE_ADJUST+'/'+a,b);},setCount:function(a,b){Arbiter.inform(CounterDisplay.EVENT_TYPE_UPDATE+'/'+a,b);}});CounterDisplay.mixin({_destroy:function(){delete this._valueNode;delete this._wrapperNode;if(this._arbiterSubscription){Arbiter.unsubscribe(this._arbiterSubscription);delete this._arbiterSubscription;}CounterDisplay.instances.remove(this);},adjustCount:function(a){this._count=Math.max(0,this._count+a);this._rm.dirty();return this;},setCount:function(a){this._count=Math.max(0,a);this._rm.dirty();return this;},paint:function(){DOM.setText(this._valueNode,this._count);if(this._wrapperNode)if(this._count<=0){hide(this._wrapperNode);if(this._statusClass&&this._statusNode)CSS.removeClass(this._statusNode,this._statusClass);}else{show(this._wrapperNode);if(this._statusClass&&this._statusNode)CSS.addClass(this._statusNode,this._statusClass);}},_subscribeAll:function(){var a=[CounterDisplay.EVENT_TYPE_ADJUST+'/'+this._name,CounterDisplay.EVENT_TYPE_UPDATE+'/'+this._name];this._arbiterSubscription=Arbiter.subscribe(a,this._onInform.bind(this),Arbiter.SUBSCRIBE_NEW);},_onInform:function(a,b){b=parseInt(b);if(isNaN(b))return;if(a.indexOf(CounterDisplay.EVENT_TYPE_ADJUST)!=-1){this.adjustCount(b);}else if(a.indexOf(CounterDisplay.EVENT_TYPE_UPDATE)!=-1){this.setCount(b);}else return;return;}});
!function(){var a={isEmpty:function(b){return (b.value||'').match(/^\s*$/)||CSS.hasClass(b,'DOMControl_placeholder');},getValue:function(b){return a.isEmpty(b)?'':b.value;}};NodeAugment.add(a,'INPUT');NodeAugment.add(a,'TEXTAREA');}();
onloadRegister(function(){Event.listen(document.documentElement,'submit',function(b){var a=b.getTarget().getElementsByTagName('*');for(var c=0;c<a.length;c++)if(a[c].getAttribute('required')&&$(a[c]).isEmpty()){a[c].focus();return false;}},Event.Priority.URGENT);});
function ChatNotificationList(){this.alertIds=[];this.alertsObj={};this.contentRoot=null;this.noItemsElement=null;this.ITEM_UNREAD_CLASS='notif_unread';this.ITEM_TAG='div';this.ITEM_CLASS='notification';this.NO_ITEMS_ID='presence_no_notifications';this.NO_ITEMS_CLASS='no_notifications';}ChatNotificationList.prototype={setUnreadItemClass:function(a){this.ITEM_UNREAD_CLASS=a;},setItemTag:function(a){this.ITEM_TAG=a;},setItemClass:function(a){this.ITEM_CLASS=a;},setNoItemsClass:function(a){this.NO_ITEMS_CLASS=a;},getAlertIds:function(){return this.alertIds;},fromDom:function(b){this.contentRoot=b;var f=this.ITEM_TAG;if(this.ITEM_CLASS)f+='.'+this.ITEM_CLASS;var d=DOM.scry(this.contentRoot,f);for(var e=0;e<d.length;e++){var c=d[e];var a=parseInt(c.getAttribute('id').replace('notification_',''),10);this.alertIds.push(a);this.alertsObj[a]=c;}this.alertIds.sort(function(g,h){return h-g;});},add:function(b,c,d){b=parseInt(b,10);if(this.alertsObj[b]){if(!d){return false;}else DOM.replace(this.alertsObj[b],HTML(c));}else{var e=-1,f=-1;for(var a=0;a<this.alertIds.length;a++)if(this.alertIds[a]<b){e=this.alertIds[a];f=a;break;}if(-1==e){if(!this.isEmpty()){DOM.appendContent(this.contentRoot,HTML(c));}else DOM.prependContent(this.contentRoot,HTML(c));this.alertIds.push(b);}else{DOM.insertBefore(HTML(c),this.alertsObj[e]);this.alertIds.splice(f,0,b);}}this.alertsObj[b]=$('notification_'+b);if(1==this.size())hide(this.NO_ITEMS_ID);return true;},hideApp:function(b,a){var d=DOM.scry(this.content,this.ITEM_TAG+'.notif_'+b);for(var c=0;c<d.length;c++)if(a){animation(d[c]).to('opacity',0).to('height',0).blind().duration(1000).hide().go();}else hide(d[c]);if(this.isEmpty())this.showNoNotifications();return d.length;},showNoNotifications:function(){if(null==this.noItemsElement)this.noItemsElement=ge(this.NO_ITEMS_ID);if(null==this.noItemsElement){this.noItemsElement=$N(this.ITEM_TAG,{id:this.NO_ITEMS_ID,className:this.NO_ITEMS_CLASS},_tx("No new notifications."));DOM.appendContent(this.contentRoot,this.noItemsElement);}show(this.NO_ITEMS_ID);},remove:function(b){var a=this.alertsObj[b];if(!this.alertsObj[b])return false;DOM.remove(a);delete this.alertsObj[b];this.alertIds.splice(this.alertIds.indexOf(b),1);if(this.isEmpty())this.showNoNotifications();return true;},getUnreadIds:function(a){var d=[];a=a||this.alertIds;for(var c=0;c<a.length;c++){var b=this.alertsObj[a[c]];if(b&&CSS.hasClass(b,this.ITEM_UNREAD_CLASS))d.push(a[c]);}return d;},markRead:function(a){for(var c=0;c<a.length;c++){var b=this.alertsObj[a[c]];animation(b).duration(1500).checkpoint().to('backgroundColor','#FFFFFF').duration(2250).ondone(CSS.removeClass.bind(null,b,this.ITEM_UNREAD_CLASS)).go();}return 0!=a.length;},addMany:function(b){var c=0;if('object'==typeof b&&!is_empty(b))for(var a in b)if(this.add(a,b[a]))c++;if(0==c&&this.isEmpty()){this.showNoNotifications();}else hide(this.NO_ITEMS_ID);return c;},isEmpty:function(){return 0==this.size();},size:function(){return this.alertIds.length;}};function ChatNotifications(b,c,g,a,d,e,f){this.count=b;this.countNew=c;this.updateTime=g;this.app_names=a;this.latest_notif_time=d;this.latest_read_notif_time=e;this.piggyback_percentage=f;this.wrapperID='presence_notifications';this.contentID='presence_notifications_content';this.navInboxID='nav_inbox';this.timeElement='span.time';this.alertList=new ChatNotificationList();this._init();}ChatNotifications.UPDATER_NAME='notifications';ChatNotifications.showReportDialog=function(a,e,g,b){if(!Dialog){var d=this.showReportDialog.bind(this,a,e,g,b);Bootloader.loadComponent('dialog',d);return;}var f={name:'hide',label:_tx("Hide all"),handler:e};var h={name:'report',label:_tx("Report Spam"),handler:g};var c={};copy_properties(c,Dialog.CANCEL);c.handler=b||bagofholding;new Dialog().setTitle(_tx("Do you want to hide all notifications from {application-name}?",{'application-name':a})).setBody(_tx("This will hide all notifications from this application. ")).setButtons([f,h,c]).setModal().show();};ChatNotifications.markAppNotificationSpam=function(a,d,b){var c={app_id:a,collapse:1,type:d};if(b)c.spam=1;new AsyncSignal('/ajax/notifications.php',c).send();};ChatNotifications.prototype={_init:function(){this.cookieName='notifications_'+Env.user;this.beepsExpiredToken=null;this.appHideCache=[];this.updateCheckCount=0;this.wrapper=ge(this.wrapperID);this.content=ge(this.contentID);this.navInbox=ge(this.navInboxID);this.countSpan=ge('presence_notifications_count');this.alertList.fromDom(this.content);this._updateCount();Arbiter.subscribe(PresenceMessage.getArbiterMessageType('notification'),this._handleNotificationMsg.bind(this));Arbiter.subscribe(PresenceMessage.getArbiterMessageType('notifications_read'),this._handleNotificationsReadMsg.bind(this));Arbiter.subscribe(PresenceMessage.PRESENCE_UPDATER_READY,this.registerForUpdates.bind(this));},registerForUpdates:function(){presenceUpdater.register(ChatNotifications.UPDATER_NAME,this._checkUpdater.bind(this),this._onUpdaterResponse.bind(this),this._onUpdaterError.bind(this),this._onUpdaterError.bind(this));},notifyRead:function(a){var b=null;if(a)b={alert_ids:a};AsyncRequest.pingURI('/ajax/presence/notifications_read.php',b);},markRead:function(c,a,b){if(this.countNew==0)return;a=a||this.alertList.getUnreadIds();this.countNew=b?b:0;this._updateCount();if(!c)this.notifyRead(a);this.alertList.markRead(a);},requiresUpdate:function(c,a,b){if(!buddyList._checkUpdater(c,{},b))return false;if(a&&undefined!=a[ChatNotifications.UPDATER_NAME])return a[ChatNotifications.UPDATER_NAME];return b||((100/(this.updateCheckCount+1))<=this.piggyback_percentage);},_checkUpdater:function(c,a,b){if(!buddyList._checkUpdater(c,{},b))return false;if(this.requiresUpdate(c,{},b)){this.updateCheckCount=0;a.notif_latest=this.latest_notif_time;a.notif_latest_read=this.latest_read_notif_time;a[ChatNotifications.UPDATER_NAME]=1;return true;}else{this.updateCheckCount++;a[ChatNotifications.UPDATER_NAME]=0;}return false;},_updateInboxMarkup:function(a,c){if(this.navInbox&&a!=null)CounterDisplay.setCount('messages_unread',a);var b=ge('fb_menu_inbox_dropdown');if(b&&c)b.setContent(HTML(c));},_updateInboxUnseenCount:function(a){return;},_onUpdaterResponse:function(a,b){this._updateInboxMarkup(a.inboxCount,a.inboxDropdownMarkup);this._updateInboxUnseenCount(a.inboxUnseen);if(!a.no_change){if(this.count!=a.count){this.count=a.count;this._signalContentChanged();}this.updateTime=b;this.latest_notif_time=a.latest_notif;this.latest_read_notif_time=a.latest_read_notif;this._addAppNames(a.app_names);this.countNew=a.countNew;this._updateDisplayDelayed();this.alertList.addMany(a.markup_map);Arbiter.inform(Arbiter.NEW_NOTIFICATIONS,a);}},_updateDisplayDelayed:function(){if(typeof Beeper!='undefined'){this.beepsExpiredToken=Arbiter.subscribe(Arbiter.BEEPS_EXPIRED,this._updateDisplay.bind(this));}else this._updateDisplay();},_updateDisplay:function(){if(!this.content)return;for(var a=0;a<this.appHideCache.length;a++)this.hideNotifications(this.appHideCache[a],true);this.appHideCache=[];this._updateCount();if(this.beepsExpiredToken)Arbiter.unsubscribe(this.beepsExpiredToken);},_onUpdaterError:function(a){},_updateCount:function(){if(this.countSpan)this.countSpan.innerHTML=this.countNew?'<strong>'+this.countNew+'</strong>':'';},hideNotifications:function(a,b){var c=this.alertList.hideApp(a,!b);this.count-=c;this._signalContentChanged();b||this.appHideCache.push(a);},showHideDialog:function(c,a,e){var d=function(g){this.hideNotifications(a);var h=('report'==g);ChatNotifications.markAppNotificationSpam(a,e,h);(typeof(toggleType)=='function')&&(typeof(hidden)!='undefined')&&(!hidden[a])&&toggleType(a,true,null,false,true,Env.user,false,e);};var d=bind(this,d,'hide');var f=bind(this,d,'report');var b=this.app_names[a]||a;ChatNotifications.showReportDialog(b,d,f);return false;},loadTab:function(){if(!this.fetch())this.markRead();},fetch:function(){var a=ge('presence_notifications_loading');if(this.alertList.size()>=5){this.fetch=bagofholding;a&&a.remove();return false;}new AsyncRequest().setURI('/ajax/presence/notifications_read.php').setStatusElement(a).setData({render:1}).setMethod('POST').setHandler(function(d){var c=d.getPayload();var b=c.markup_map;this.alertList.addMany(b);this._addAppNames(c.app_names);a&&a.remove();this.markRead(true);this.fetch=bagofholding;}.bind(this)).send();return true;},_addAppNames:function(a){a&&copy_properties(this.app_names,a);},_mergeNotification:function(b,c,d,a){if(!this.alertList.add(b,c))return;this.count++;if(d)this.countNew++;this._updateCount();a&&this._addAppNames(a);if(this.isTabOpen())this._merged_mouseover_handler=this.content.listen('mouseover',(function(){this._merged_mouseover_handler.remove();this.markRead();}).bind(this));},_handleNotificationMsg:function(c,a){var b=a.obj;if(b.markup){this._mergeNotification(b.alert_id,b.markup,b.unread,b.app_names);}else presenceUpdater.runHandler('notifications');},_handleNotificationsReadMsg:function(c,a){var b=a.obj;if(typeof Beeper!='undefined')Beeper.getInstance().markRead(true,b.alert_ids);this.markRead(true,b.alert_ids,b.num_unread);},_signalContentChanged:function(){if(window.presence)presence.contentChanged(this.contentID);},isTabOpen:function(){return presence.focusedTab=='presence_notifications_tab';}};

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