/*
HTTP Host: static.ak.fbcdn.net
Generated: March 16th 2010 12:24:19 PM PDT
Machine: 10.16.140.102
Locale: nu_ll
Path: js/blzdtt54tsocwg88.pkg.js
*/

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

var CrossDocument={};(function(){CrossDocument.setListener=function(a){if(window.postMessage){if(window.addEventListener){window.addEventListener('message',a,false);}else window.onmessage=a;}else if(document.postMessage)document.addEventListener('message',a,false);};CrossDocument.mkPostMessage=function(c,b,a){if(window.postMessage){if("object"==typeof window.postMessage){return function(d,e){c.postMessage(d,e);};}else return bind(c,c.postMessage);}else if(document.postMessage){return bind(b,b.postMessage);}else return bind(c,a);};CrossDocument.targetOrigin=function(a){if(window.postMessage||document.postMessage){var c=a.location;var b=c.hostname;if(b=='facebook.com'||b.substring(b.length-13)=='.facebook.com')return c.protocol+'//'+c.host;}else return null;};var _handleMessage=function(msgCallback,msgStr){if(!msgStr||msgStr.charAt(0)!='{')return;var msg=eval('('+msgStr+')');return msgCallback(msg);};CrossDocument.mkEventHandler=function(a){return function(event){event=event||window.event;var b=(event.domain||event.origin);if(b.substring(b.length-13)!='.facebook.com'&&b.substring(b.length-15)!='://facebook.com'&&b!='facebook.com')return;return _handleMessage(a,event.data);};};CrossDocument.mkMessageHandler=function(a){return function(b){return _handleMessage(a,b);};};})();
PresenceMessage={STARTED:'presence/started',SHUTDOWN:'presence/shutdown',RESTARTED:'presence/restarted',WINDOW_RESIZED:'presence/window-resized',TAB_CLOSED:'presence/tab-closed',TAB_OPENED:'presence/tab-opened',PRESENCE_UPDATER_READY:'presence/updater-ready',getAppMessageType:function(a,b){return 'presence/app_message:'+a+':'+b;},getArbiterMessageType:function(a){return 'presence/message:'+a;}};
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;}});
function rand32(){return Math.floor(Math.random()*4294967295);}function verifyNumber(a){if(typeof a=='undefined'||isNaN(a)||a==Number.POSITIVE_INFINITY||a==Number.NEGATIVE_INFINITY)a=0;return a;}
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('');}};
Dcode=function(){var a,d={},b={_:'%',A:'%22%3a',B:'%2c%22',C:'%2c%22sb%22%3a1%2c%22t%22%3a%7b%7d%2c%22f%22%3anull%2c%22uct%22%3a0%2c%22s%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a',D:'%7b%22',E:'%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22blo%22%3a0%2c%22bvt%22%3a',F:'ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1',G:'%2c%22ch%22%3a%7b%22h%22%3a%22channel',H:'%22%2c%22p%22%3a80%2c%22sub%22%3a%5b',I:'%7d%7d',J:'%7b%22v%22%3a2%2c%22time%22%3a1',K:'%2c%22lc%22%3a1%2c%22cvr%22%3a%7b%22r%22%3a1%2c%22ts%22%3a1',L:'%5d%2c%22p%5f',M:'%22%3a0%2c%22',N:'%22%3a%7b%22i%22%3a0%2c%22all%46lids%22%3a%5bnull%5d',O:'0000',P:'%22%3a1',Q:'%7d',R:'%2c%22pt%22%3a0%2c%22vis%22%3a0%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22blo%22%3a0%2c%22bvt%22%3a0%2c%22ct%22%3a0%2c%22sb%22%3a1%2c%22t%22%3a%7b%7d%2c%22f%22%3anull%2c%22uct%22%3a0%2c%22s%22%3a0%7d%2c2bl%22%3a%7b%22ac%22%3a0%2c%22ut',S:'%22%3a%7b%22ol%22%3a%2d1%2c%22exp%22%3a1',T:'fl%22%3a%5b%22%2d1%22%5d%2c%22all%46lids%22%3a%5b%22%2d1%22%5d',U:'ud%22%3a900%2c%22lc%22%3a0%2c%22cvr%22%3a%7b',V:'%2c%22ut%22%3a1',W:'%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls',X:'%2c%22lc%22%3a1%2c%22cvr%22%3a%7b%22r%22%3a0%2e',Y:'%22%3a%7b%22n%22%3a%22%',Z:'%2c%22ud%22%3a'};function c(){var f=[];for(var e in b){d[b[e]]=e;f.push(b[e]);}f.reverse();a=new RegExp(f.join("|"),'g');}return {encode:function(e){c();return encodeURIComponent(e).replace(/([_A-Z])|%../g,function(g,f){return f?'%'+f.charCodeAt(0).toString(16):g;}).toLowerCase().replace(a,function(f){return d[f];});},decode:function(e){return decodeURIComponent(e.replace(/[_A-Z]/g,function(f){return b[f];}));}};}();
function CookieManager(d,c,a,b){this.version=d;this.cookieName='presence';this.stripQuotes=c;this.base64Encode=a;this.dictEncode=b;this.storers={};}CookieManager.prototype={register:function(b,a){this.storers[b]=a;},store:function(){var a=this._getCookie();if(a&&a.v&&this.version<a.v){presence.versionShutdown();return;}var b={v:this.version,time:parseInt(presence.getTime()*.001)};for(var d in this.storers)b[d]=this.storers[d]();var c=JSON.encode(b);if(this.stripQuotes)c=c.replace(/"([a-zA-Z0-9_]+?)":/g,'$1:');if(this.dictEncode){c='D'+Dcode.encode(c);}else if(this.base64Encode)c='b'+Base64.encode(c);setCookie(this.cookieName,c,null);},_getCookie:function(){try{var a=getCookie(this.cookieName);if(this.lastD===a){return this.lastV;}else{this.lastD=a;this.lastV=null;}if(a&&a.charAt(0)=='D'){a=Dcode.decode(a.substring(1));}else if(a&&a.length>1&&a.charAt(0)=='b'){a=Base64.decode(a.substring(1));a=a.replace(/([,{])([a-zA-Z0-9_]+?):/g,'$1"$2":');}if(a)return this.lastV=JSON.decode(a);}catch(e){}return null;},getSubCookie:function(b){var a=this._getCookie();if(!a)return null;return a[b];}};
function ChannelManager(e,d,a,c,b){this.user=e;this.iframeCheckTime=16000;this.iframeCheckRetryTime=16000;this.iframeLoadMaxRetries=1;this.retryInterval=d;this.channelConfig=a;this._init(c);this.loginErrorGk=b;}ChannelManager.prototype={_init:function(c){this.channels={};this.iframeHost=this.iframePort=null;this.isActionRequest=true;this.isReady=false;this.isRebuilding=false;this.iframeIsLoaded=false;this.iframeEverLoaded=false;this.iframeCheckFailedCount=0;this.permaShutdown=false;this.shouldClearSubdomain=false;this.subframe=ge('channel_iframe');this.postMessage=null;var a=presenceCookieManager.getSubCookie('ch');if(c){this.iframeSubdomain=null;}else{this.iframeSubdomain=0;if(a&&a.sub){for(var b=0;b<a.sub.length;b++)if(!a.sub[b]){this.iframeSubdomain=b;break;}if(b==a.sub.length)this.iframeSubdomain=a.sub.length;}}var d=ua.safari();this.pollForMessages=(d>523&&d<525);this.useRandomSubdomain=!!ua.ie();this.handleIframeEvent=CrossDocument.mkEventHandler(this._handleIframeMessage.bind(this));this.handleIframeMessage=CrossDocument.mkMessageHandler(this._handleIframeMessage.bind(this));CrossDocument.setListener(this.handleIframeEvent.bind(this));presenceCookieManager.register('ch',this._getCookieInfo.bind(this));if(ua.firefox()){onbeforeunloadRegister(this._onUnload.bind(this));}else onunloadRegister(this._onUnload.bind(this));},sendiFrameMessage:function(a){if(!this.postMessage)return;var b=JSON.encode(a);try{this.postMessage(b,this.targetOrigin);}catch(e){presence.error('channel: error sending message "'+b+'" to iframe: '+e.toString());}},_handleIframeMessage:function(a){if(a.type=='init'){this.iframeLoaded();}else if(a.type=='channelMsg')this.handleChannelMsg(a.channel,a.seq,a.msg);},_onUnload:function(){this.shouldClearSubdomain=true;presence.doSync(true);},addChannel:function(a,d,b,f,e,c){this.channels[a]={currentSeq:d,nextSeq:0,msgHandler:b,startHandler:f,shutdownHandler:e,restartHandler:c};},_getCookieInfo:function(){var c={};if(this.iframeHost&&this.iframePort){c.h=this.iframeHost;c.p=this.iframePort;if(null!==this.iframeSubdomain){var b=presenceCookieManager.getSubCookie('ch');var f=(b&&b.sub)?b.sub:[];var e=f.length;if(this.shouldClearSubdomain){f[this.iframeSubdomain]=0;}else{f[this.iframeSubdomain]=1;for(var d=e;d<=this.iframeSubdomain;d++)if(!f[d])f[d]=0;}c.sub=f;}for(var a in this.channels)c[a]=this.channels[a].currentSeq;}c.ri=this.retryInterval;return c;},stop:function(){this.stopped=true;this.setReady(false);},setReady:function(a){this.isReady=a;var b={type:'isReady',isReady:a,isActionRequest:this.isActionRequest};if(a&&this.isActionRequest)this.isActionRequest=false;if(a)b.channels=this.channels;this.sendiFrameMessage(b);},setActionRequest:function(a){this.sendiFrameMessage({type:'isActionRequest',isActionRequest:a});},iframeLoad:function(c,a,d,b){this.isReady=b;this.iframeIsLoaded=false;this.iframePath=c;this.iframeHost=a;this.iframePort=d;var e;if(null===this.iframeSubdomain){e='';}else{e=this.iframeSubdomain;if(this.useRandomSubdomain)e+=''+rand32();e+='.';}var g='http://'+e+this.iframeHost+'.facebook.com:'+this.iframePort+this.iframePath;this._iframeCheck.bind(this).defer(this.iframeCheckTime);var f=null;try{f=this.subframe.contentDocument;}catch(e){}if(f){try{f.location.replace(g);}catch(e){presence.error('channel: error setting location: '+e.toString());}}else if(this.subframe.contentWindow){this.subframe.src=g;}else if(this.subframe.document){this.subframe.src=g;}else presence.error('channel: error setting subframe url');presence.debug('channel: done with iframeLoad, subframe sent to '+g);},iframeLoaded:function(){if(!this.iframeIsLoaded){this.iframeIsLoaded=true;this.postMessage=CrossDocument.mkPostMessage(this.subframe.contentWindow,this.subframe.contentDocument,this.subframe.contentWindow.channelUplink.handleParentMessage);this.targetOrigin="*";this.setReady(this.isReady);if(this.pollForMessages)this.msgCheckInterval=setInterval(this.handleChannelMsgCheck.bind(this),100);if(this.iframeCheckFailedCount){for(var a in this.channels)this.channels[a].restartHandler(false);this._sendDummyReconnect(ChannelRebuildReasons.IFrameLoadRetryWorked);}else for(var a in this.channels)this.channels[a].startHandler();this.iframeCheckFailedCount=0;this.iframeEverLoaded=true;}},_iframeCheck:function(){if(!this.iframeIsLoaded){presence.error("channel: uplink iframe never loaded; shutting down");this.iframeCheckFailedCount++;this.iframeHost=this.iframePort=0;presenceCookieManager.store();if(this.iframeCheckFailedCount<=this.iframeLoadMaxRetries){this.iframeCheckTime=this.iframeCheckRetryTime;this.iframePath=null;this.rebuild(ChannelRebuildReasons.IFrameLoadRetry);}else{for(var a in this.channels)this.channels[a].shutdownHandler();this._sendDummyReconnect(ChannelRebuildReasons.IFrameLoadGiveUp);}}else{this.retryInterval=0;presence.debug('channel: uplink iframe loaded fine');}},_sendDummyReconnect:function(b){var a=new AsyncRequest().setURI('/ajax/presence/reconnect.php').setData({reason:b,iframe_loaded:this.iframeEverLoaded}).setOption('suppressErrorHandlerWarning',true).setMethod('GET').setReadOnly(true);a.specifiesWriteRequiredParams()&&a.send();},_rebuildResponse:function(d){var c=d.getPayload();var b=c.user_channel;presence.debug('got rebuild response with channel '+b+', seq '+c.seq+', host '+c.host+', port '+c.port);this.channels[b].currentSeq=c.seq;this.channels[b].nextSeq=0;this.isRebuilding=false;if(c.path!=this.iframePath||c.host!=this.iframeHost||c.port!=this.iframePort){this.iframeLoad(c.path,c.host,c.port,true);}else this.setReady(true);presenceCookieManager.store();presenceUpdater.pauseUpdate();if(typeof chatOptions!='undefined')chatOptions.setVisibility(c.visibility);for(var a in this.channels)this.channels[a].restartHandler(true);presenceUpdater.resumeUpdate(['buddy_list']);},_retryRebuild:function(c,a){if(a){this.retryInterval=this.channelConfig.MAX_RETRY_INTERVAL;}else if(this.retryInterval==0){this.retryInterval=this.channelConfig.MIN_RETRY_INTERVAL;}else{this.retryInterval*=2;if(this.retryInterval>=this.channelConfig.MAX_RETRY_INTERVAL)this.retryInterval=this.channelConfig.MAX_RETRY_INTERVAL;}var b=this.retryInterval*(.75+Math.random()*.5);presence.warn('manager trying again in '+(b*.001)+' secs');setTimeout(this._rebuildSend.bind(this,c),this.retryInterval);},_rebuildError:function(b,c){for(var a in this.channels)this.channels[a].shutdownHandler(true);presence.error('got rebuild error: '+c.getErrorDescription());if(presence.checkMaintenanceError(c)){presence.warn('manager not trying again');}else if(presence.checkLoginError(c)){if(presence.inPopoutWindow||this.loginErrorGk){this._retryRebuild(ChannelRebuildReasons.PrevFailed,true);}else presence.warn('manager not trying again');}else this._retryRebuild(ChannelRebuildReasons.PrevFailed,false);},_rebuildTransportError:function(b,c){for(var a in this.channels)this.channels[a].shutdownHandler(true);presence.error('got rebuild transport error: '+c.getErrorDescription());this._retryRebuild(b,false);},_rebuildSend:function(b){if(typeof b!='number')b=ChannelRebuildReasons.Unknown;presence.debug('channel: sending rebuild');var a=new AsyncRequest().setURI('/ajax/presence/reconnect.php').setData({reason:b,iframe_loaded:this.iframeEverLoaded}).setHandler(this._rebuildResponse.bind(this)).setErrorHandler(this._rebuildError.bind(this,b)).setTransportErrorHandler(this._rebuildTransportError.bind(this,b)).setOption('suppressErrorAlerts',true).setMethod('GET').setReadOnly(true);return a.specifiesWriteRequiredParams()&&a.send();},rebuild:function(a){if(this.stopped)return;if(this.isRebuilding){presence.debug('channel: rebuild called, but already rebuilding');return;}this.setReady(false);this.isRebuilding=true;presence.debug('channel: rebuilding');if(a==ChannelRebuildReasons.RefreshDelay)this.retryInterval=this.channelConfig.MAX_RETRY_INTERVAL;setTimeout(this._rebuildSend.bind(this,a),this.retryInterval);},handleChannelMsgCheck:function(){if(this.pendingMsg){this._handleChannelMsg(this.pendingMsg.channel,this.pendingMsg.seq,this.pendingMsg.msg);this.pendingMsg=null;}},handleChannelMsg:function(a,c,b){if(this.pollForMessages){this.pendingMsg={channel:a,seq:c,msg:b};}else this._handleChannelMsg(a,c,b);},_handleChannelMsg:function(b,e,c){if(c.type=='shutdown'||c.type=='permaShutdown'){if(!window.loaded||this.permaShutdown)return;if(c.type=='permaShutdown'){presence.warn('channel: got permaShutdown for all channels');this.permaShutdown=true;}else{presence.warn('channel: got shutdown for all channels');this.rebuild(c.reason);}for(var a in this.channels)this.channels[a].shutdownHandler(true);}else{this.channels[b].currentSeq++;var d;if((d=this.channels[b].nextSeq)&&e<d){presence.warn('ignoring a duplicate message ('+e+')<('+d+') on '+b);return;}this.channels[b].nextSeq=parseInt(e)+1;presence.pauseSync();try{this.channels[b].msgHandler(b,c);}catch(e){presence.error('error in channel handlers: '+e.toString()+', msg: '+c);}presence.resumeSync();}}};
function fbx_ab_log_click(b){var a={link_name:b};new AsyncSignal('/ajax/fbx_logging.php',a).send();}
function LiveMessageReceiver(a){this.eventName=a;this.subs=null;this.handler=bagofholding;this.shutdownHandler=null;this.restartHandler=null;this.registered=false;this.appId=1;}LiveMessageReceiver.prototype.setAppId=function(a){this.appId=a;return this;};LiveMessageReceiver.prototype.setHandler=function(a){this.handler=a;this._dirty();return this;};LiveMessageReceiver.prototype.setRestartHandler=function(a){this.restartHandler=a.shield();this._dirty();return this;};LiveMessageReceiver.prototype.setShutdownHandler=function(a){this.shutdownHandler=a.shield();this._dirty();return this;};LiveMessageReceiver.prototype._dirty=function(){if(this.registered){this.unregister();this.register();}};LiveMessageReceiver.prototype.register=function(){var b=function(d,c){return this.handler(c);}.bind(this);var a=PresenceMessage.getAppMessageType(this.appId,this.eventName);this.subs={};this.subs.main=Arbiter.subscribe(a,b);if(this.shutdownHandler)this.subs.shut=Arbiter.subscribe(PresenceMessage.SHUTDOWN,this.shutdownHandler);if(this.restartHandler)this.subs.restart=Arbiter.subscribe(PresenceMessage.RESTARTED,this.restartHandler);this.registered=true;return this;};LiveMessageReceiver.prototype.unregister=function(){if(!this.subs)return this;for(var a in this.subs)if(this.subs[a])Arbiter.unsubscribe(this.subs[a]);this.subs=null;this.registered=false;return this;};LiveMessageReceiver.route=function(b){var a=function(c){var d=PresenceMessage.getAppMessageType(b.app_id,b.event_name);Arbiter.inform(d,c,Arbiter.BEHAVIOR_PERSISTENT);};if(b.hasCapture){new AsyncRequest().setHandler(function(c){a(c.getPayload());}).handleResponse(b.response);}else a(b.response);};
function Presence(i,e,c,g,f,h){this.user=i;this.name=e;this.firstName=c;this.sitevars=h;this.popoutURL=env_get('www_base')+'presence/popout.php';var j=Vector2.getViewportDimensions();this.maxTabOffset=37;var b=['fb_menubar','intern_bookmark_frame'];var a;for(var d=0;d<b.length;d++)if(a=ge(b[d]))this.maxTabOffset+=Vector2.getElementDimensions(a).y;this.maxTabHeight=j.y-this.maxTabOffset;this.updateServerTime(g);this.pageLoadTime=this.getTime();this._init(f);}Presence.prototype={minWidth:100,minHeight:100,defWidth:900,defHeight:650,defX:30,defY:30,cookiePollTime:2000,popoutHeartbeatTime:1000,popoutHeartbeatAllowance:4000,popoutHeartbeatFirstAllowance:15000,resizeStopTime:500,shutdownDelay:5000,restartDelay:3000,POPOUT_TYPE_CHAT:1,POPOUT_TYPE_VIDEOCHAT:2,_init:function(b){this.stateStorers=[];this.stateLoaders=[];this.windowID=rand32()+1;this.contentPaddings={buddy_list:77,presence_notifications:23,presence_applications:99};this.contentResized={};this.holder=$('presence');this.holderUI=$('presence_ui');this.bar=$('presence_bar');this.popoutSidebar=ge('presence_popout_sidebar');this.popoutWidth=this.defWidth;this.popoutHeight=this.defHeight;this.cookiePoller=null;this.heartbeat=null;this.resizeTimeout=null;this.lastResized=0;this.stateUpdateTime=0;this.loaded=false;this.isShutdown=false;this.isShuttingDown=false;this.isRestarting=false;this.isPermaShutdown=false;this.shutdownTime=0;this.popoutClicked=false;this.popinClicked=false;this.justPoppedOut=false;this.syncPaused=0;this.disableUnfocus=null;this.tempTabCloseHandler=null;this.inPopoutWindow=b==this.POPOUT_TYPE_CHAT;this.inVideoChat=b==this.POPOUT_TYPE_VIDEOCHAT;this.inVideoChatWith=null;this.poppedOut=this.inPopoutWindow;presenceCookieManager.register('state',this._getCookieData.bind(this));if(this.inPopoutWindow){Util.fallbackErrorHandler=null;if(!this.inVideoChat)this.bar.style.marginRight='200px';if(!this.inVideoChat){onbeforeunloadRegister(this.popin.bind(this,false));onunloadRegister(this.popin.bind(this,false));}}Event.listen(window,'resize',this._windowOnResize.bind(this));Event.listen(window,'keypress',this._documentKeyPress.bind(this));Event.listen(document,'click',this._documentOnClick.bind(this));if(DOMScroll.usingScrollWrapper())DOMScroll.registerScrollChangeHandler(this._handleScrollChange.bind(this));Arbiter.subscribe(Arbiter.PAGE_TRANSITION,this.checkRebuild.bind(this));var c=ua.safari();this.isSafari2=(c&&c<500);this.isOpera=(ua.opera()>0);var a=ua.firefox();this.isFF2=(a&&a<3);this.isWindows=ua.windows();this.load();this._windowOnResize.bind(this).defer();if(this.inPopoutWindow)setTimeout(this._windowOnResize.bind(this),3000);},updateServerTime:function(a){this.timeSkew=(new Date()).getTime()-a;},getTime:function(){return (new Date()).getTime()-this.timeSkew;},debug:function(a){},warn:function(a){},error:function(a){},inVideoCallTo:function(a){this.inVideoChatWith=a;},load:function(){var a=presenceCookieManager.getSubCookie('state');if(!a){this.debug('presence: got null state cookie, loading with current state');this._load(this._getCookieData());return;}try{this._load(a);}catch(e){this.error('presence: got load exception: '+e.toString());this._load(this._getCookieData());}},_load:function(b){this.syncPaused++;this.stateUpdateTime=verifyNumber(b.ut);this.popoutTime=verifyNumber(b.pt);this.poppedOut=!!b.p;if(this.poppedOut){if(this.inPopoutWindow){if(!this.heartbeat&&!this.inVideoChat)this.heartbeat=setInterval(this._popoutHeartbeat.bind(this),this.popoutHeartbeatTime);}else CSS.addClass(this.holder,'popped_out');}else if(!this.inVideoChat){if(this.inPopoutWindow){if(!this.loaded){this.poppedOut=true;this.doSync();}else if(!this.popinClicked)window.close();}else this.justPoppedOut=true;CSS.removeClass(this.holder,'popped_out');}if(!this.inPopoutWindow&&!this.cookiePoller)this.cookiePoller=setInterval(this._pollCookie.bind(this),this.cookiePollTime);this.state=b;for(var a=0;a<this.stateLoaders.length;a++)this.stateLoaders[a](b);this._handleResize.bind(this,0,0).defer();setTimeout(this._handleResize.bind(this,0,0),100);this.syncPaused--;this.loaded=true;},_pollCookie:function(){var e=presenceCookieManager.getSubCookie('state');if(!e)return;var d=this.popoutTime;if(e.ut>this.stateUpdateTime){this.load(e);return;}if(this.poppedOut&&!this.inPopoutWindow){var a=verifyNumber(e.pt);var b=(new Date()).getTime()-a;var c=this.popoutHeartbeatTime+this.popoutHeartbeatAllowance;if(this.justPoppedOut)if(a==d){c+=this.popoutHeartbeatFirstAllowance;}else this.justPoppedOut=false;this.popoutTime=a;if(b>c){this.poppedOut=false;this.doSync();}}},_popoutHeartbeat:function(){this._pollCookie();if(this.poppedOut)presenceCookieManager.store();},_getCookieData:function(){var b={p:this.poppedOut?1:0,ut:this.stateUpdateTime,pt:this.inPopoutWindow?(new Date()).getTime():this.popoutTime};for(var a=0;a<this.stateStorers.length;a++)b=this.stateStorers[a](b);this.state=b;return this.state;},doSync:function(a){if(this.syncPaused)return;if(a){this._doSync();}else this._doSync.bind(this).defer();},_doSync:function(){this.stateUpdateTime=(new Date()).getTime();presenceCookieManager.store();this._load(this.state);},pauseSync:function(){this.syncPaused++;},resumeSync:function(){this.syncPaused--;this.doSync();},handleMsg:function(a,b){this._handleMsg.bind(this,a,b).defer();},_handleMsg:function(a,b){if(typeof b=='string'){if(b=='shutdown'){this.connectionShutdown();}else if(b=='restart')if(this.isShutdown)this.restart();return;}if(this.isShutdown)return false;if(!b.type)return;if(b.type=='app_msg')if(b.event_name=='beep_event'){Bootloader.loadComponents('beeper',function(){Beeper.ensureInitialized();LiveMessageReceiver.route(b);});}else LiveMessageReceiver.route(b);Arbiter.inform(PresenceMessage.getArbiterMessageType(b.type),{sender:this,channel:a,obj:b});},popout:function(){if(this.inVideoChat)return;if(this.inPopoutWindow||this.poppedOut){this.popin(true);return;}if(this.popoutClicked)return;this.popoutClicked=true;var a=window.open(this.popoutURL,"fbChatWindow","status=0,toolbar=0,location=0,menubar=0,"+"directories=0,resizable=1,scrollbars=0,"+"width="+this.popoutWidth+",height="+this.popoutHeight+","+"left="+this.defX+",top="+this.defY);CSS.removeClass(this.holder,'popped_out');this.poppedOut=true;this.justPoppedOut=true;this.popoutTime=(new Date()).getTime();this.doSync();this.popoutClicked=false;},popin:function(a){if(this.inVideoChat)return;if(typeof a=='undefined')a=true;if(this.inPopoutWindow){if(this.popinClicked)return;this.popinClicked=true;}this.poppedOut=false;this.doSync();if(this.inPopoutWindow&&a)window.close();},_windowOnResize:function(){this.contentResized={};var a=Vector2.getViewportDimensions();this._handleResize(a.x-this.virtPopoutWidth,a.y-this.virtPopoutHeight);if(!this.inPopoutWindow){this._updateMaxTabHeight();}else this.popoutHeight=a.y;},_updateMaxTabHeight:function(){this.maxTabHeight=Vector2.getViewportDimensions().y-this.maxTabOffset;if(DOMScroll.usingScrollWrapper()&&DOMScroll.getScrollState().x)this.maxTabHeight-=DOMScroll.getScrollbarSize();if(window.buddyList&&buddyList.buddyListOpen){buddyList.resizeTab();}else if(this.focusedWrapper&&this.focusedContent)this.tabContentResize(this.focusedWrapper,this.focusedContent);},_handleScrollChange:function(f,d){if(!DOMScroll.usingScrollWrapper())return;var e=DOMScroll.getScrollbarSize();var a=this.getHolderBottomPosition();var b=15+(d.is_scrolled.y?e:0);CSS.setStyle(this.holder,'bottom',a+'px');CSS.setStyle(this.holderUI,'marginRight',b+'px');if(typeof chatDisplay!='undefined')for(var c in chatDisplay.tabs)chatDisplay.tabs[c].adjustWrapperBottom();this._updateMaxTabHeight();},getHolderBottomPosition:function(){var a=0;if(DOMScroll.getScrollState().x){var b=DOMScroll.getScrollbarSize();a=b+(ua.osx()?1:0);}if(presence.isIE6)a--;return a;},_handleResize:function(b,c){var a=this.loaded?100:10;if(this.handleResizeTimer)clearTimeout(this.handleResizeTimer);this.handleResizeTimer=setTimeout(function(){this.virtPopoutWidth+=b;this.virtPopoutHeight+=c;this.popoutWidth=Math.max(this.virtPopoutWidth,this.minWidth);this.popoutHeight=Math.max(this.virtPopoutHeight,this.minHeight);Arbiter.inform(PresenceMessage.WINDOW_RESIZED,{sender:this});},a);},_stopResize:function(){if(this.virtPopoutWidth!=this.popoutWidth||this.virtPopoutHeight!=this.popoutHeight){this.virtPopoutWidth=this.popoutWidth;this.virtPopoutHeight=this.popoutHeight;this.doSync();}},_documentKeyPress:function(a){a=$E(a);var b=a?a.keyCode:-1;if(b==KEYS.ESC)Event.kill(a);},_documentOnClick:function(event){if(DOM.contains(this.holder,event.getTarget())||!DOM.contains(document,event.getTarget()))return;if((typeof buddyList!='undefined')&&buddyList.buddyListOpen){if(typeof buddyListDisplay!='undefined'&&buddyListDisplay.isFlyoutOpen()){buddyListDisplay.closeOpenFlyout();return;}if(!buddyList.isSticky())buddyList.closeTab();}else this.closeTab();},_unfocus:function(){if(this.focusedWrapper)hide(this.focusedWrapper);if(this.focusedTab){CSS.removeClass(ge(this.focusedTab),'focused');if(this.tempTabCloseHandler){this.tempTabCloseHandler();this.tempTabCloseHandler=null;}}this.wasFocusedTab=this.focusedTab;this.focusedTab=this.focusedWrapper=null;return this.wasFocusedTab;},unfocus:function(){var a=this._unfocus();if(a){this.disableUnfocus=a;setTimeout(function(){this.disableUnfocus=null;}.bind(this),50);}},toggleTab:function(f,d,a,b){var e=ge(f);var c=ge(d);if(!e||!c||d==this.disableUnfocus)return;if(e.style.display=='none'){this.openTab(f,d,a);if(b)fbx_ab_log_click('NOTIFICATIONS_TAB');}else this.closeTab();},closeTab:function(){var a=this.focusedTab;if(!a)return;var b=this.wasFocusedTab;this.unfocus();CSS.removeClass(a,'focused');CSS.removeClass(this.holder,'tab_open');Arbiter.inform(PresenceMessage.TAB_CLOSED,{sender:this,tabID:a});if(a!=b&&b=='buddy_list_tab')buddyList.openTab();},openTabDelayed:function(c,b,a){this.openTab.bind(this,c,b,a).defer();},openTab:function(c,b,a){if(this.focusedTab==b)return;this._unfocus();this.focusedWrapper=c;this.focusedContent=a;this.focusedTab=b;this.disableUnfocus=this.focusedTab;setTimeout(function(){this.disableUnfocus=null;}.bind(this),50);if(a&&!this.contentResized[a]){ge(c).style.visibility='hidden';show(c);this.tabContentResize(c,a);ge(c).style.visibility='';}else show(c);CSS.addClass(ge(b),'focused');CSS.addClass(this.holder,'tab_open');Arbiter.inform(PresenceMessage.TAB_OPENED,{sender:this,tabID:b});},contentChanged:function(a){delete this.contentResized[a];},tabContentResize:function(i,b,f){if(this.poppedOut||this.inVideoChat)return;var a=ge(b);var h=ge(i);if(!a||!h)return;var c=a.parentNode;if(this.focusedWrapper==i)this.contentResized[b]=true;if(!this.contentPaddings[i]){var e=Vector2.getHiddenElementDimensions(h);var d=Vector2.getHiddenElementDimensions(c);this.contentPaddings[i]=e.y-d.y;}if(ua.ie()<8){c.style.height='auto';dimContent=Vector2.getHiddenElementDimensions(c);}else dimContent=Vector2.getHiddenElementDimensions(a);var g=this.maxTabHeight-this.contentPaddings[i];if(dimContent.y&&dimContent.y<g){CSS.removeClass(c,'scroll');c.style.height=f?(dimContent.y+'px'):'auto';}else{CSS.addClass(c,'scroll');c.style.height=g+'px';}},pauseOffClick:function(a){this.disableUnfocus=a;},resumeOffClick:function(){this.disableUnfocus=null;},renderLink:function(b,c,a){return '<a href="'+b+'"'+(this.inPopoutWindow||this.inVideoChat?' target="_blank"':'')+(a?a:'')+'>'+c+'</a>';},checkRebuild:function(){if(this.isShutdown&&!this.isPermaShutdown)channelManager.rebuild(ChannelRebuildReasons.PageTransitionRetry);},getErrorDescription:function(a){var c=a.getError();var b=a.getErrorDescription();if(!b)b=_tx("Si \u00e8 verificato un errore");if(c==kError_Async_NotLoggedIn)b=_tx("La tua sessione \u00e8 scaduta. Accedi nuovamente.");return b;},showAsyncError:function(a,d){if(typeof d=='undefined'||!d){var b=_tx("Chat");d=_tx("Errore della chat di Facebook\n");}var c=this.getErrorDescription(a);new ErrorDialog().showError(d,c);},showTransportError:function(a,d){if(typeof d=='undefined'||!d){var b=_tx("Chat");d=_tx("Errore della chat di Facebook\n");}var c=_tx("Impossibile connettersi alla {Chat} di Facebook in questo momento.",{Chat:_tx("Chat")});new ErrorDialog().showError(d,c);this.warn("presence: got async transport error: "+a.getErrorDescription());},checkLoginError:function(a){var b=a.getError();if(b==kError_Async_NotLoggedIn||b==kError_Async_LoginChanged||b==kError_Async_CSRFCheckFailed||b==kError_Login_GenericError){this.loginShutdown();return true;}return false;},checkMaintenanceError:function(a){if(a.getError()==1356007){this.maintenanceShutdown();return true;}return false;},permaShutdown:function(){this.isPermaShutdown=true;this.shutdown();},loginShutdown:function(){var a=_tx("La tua sessione \u00e8 scaduta. Accedi nuovamente.");this.shutdown(false,a);},connectionShutdown:function(b){var a=_tx("Impossibile connettersi alla {Chat} di Facebook in questo momento.",{Chat:_tx("Chat")});this.shutdown(b,a);},maintenanceShutdown:function(){var a=_tx("La {Chat} di Facebook non \u00e8 disponibile a causa di manutenzione .",{Chat:_tx("Chat")});this.shutdown(false,a);channelManager.stop();},versionShutdown:function(){var a=_tx("Aggiorna la pagina per ottenere l'ultima versione della {Chat} di Facebook.",{Chat:_tx("Chat")});this.shutdown(false,a);channelManager.stop();},shutdown:function(c,b){this.isRestarting=false;this.isShuttingDown=true;var a=(new Date()).getTime();this.shutdownTime=a;if(!c){this._shutdown(b,0);}else setTimeout(this._shutdown.bind(this,b,a),this.shutdownDelay);},_shutdown:function(a,b){if(!this.isShuttingDown&&b==this.shutdownTime)return;if(b&&this.isShutdown)return;if(typeof a!='string'||!a)a=_tx("Facebook {Chat} sta avendo problemi tecnici.",{Chat:_tx("Chat")});if(!this.inPopoutWindow){CSS.addClass(this.holder,'presence_error');set_inner_html($('presence_error_reason'),a);}else{if(this.shutdownErrorDialog)this.shutdownErrorDialog.hide();this.shutdownErrorDialog=new ErrorDialog().setTitle(_tx("Errore della chat di Facebook\n")).setBody(a).show();}if(this.isShutdown)return;this.warn("presence: shutting down");this.isShutdown=true;Arbiter.inform(PresenceMessage.SHUTDOWN,{sender:this});},restart:function(a){this.isShuttingDown=false;this.isRestarting=true;if(!a){this._restart(0);}else setTimeout(this._restart.bind(this,this.shutdownTime),this.restartDelay);},_restart:function(a){if(!this.isRestarting||(a&&a!=this.shutdownTime))return;this.debug("presence: restarting");this.isShutdown=false;this.load();Arbiter.inform(PresenceMessage.RESTARTED,{sender:this});if(!this.inPopoutWindow){CSS.removeClass(this.holder,'presence_error');}else if(this.shutdownErrorDialog)this.shutdownErrorDialog.hide();},start:function(){Arbiter.inform(PresenceMessage.STARTED,{sender:this});},registerStateStorer:function(a){this.stateStorers.push(a);},registerStateLoader:function(a){this.stateLoaders.push(a);},registerTempTabCloseHandler:function(a){this.tempTabCloseHandler=a;}};function getFirstName(c){var d=c.split(" ");var b=d[0];var a=b.length;if(typeof d[1]!='undefined'&&(a==1||(a==2&&b.indexOf('.')!=-1)||(a==3&&b.toLowerCase()=='the')))b+=' '+d[1];return b;}
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("Non \u00e8 stato possibile azzerare la cronologia della {Chat}",{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("invia come messaggio"),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("Impossibile connettersi alla {Chat} di Facebook in questo momento.",{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("Invio in corso")+'</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("Mostra\/Nascondi la Finestra {Chat}",{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("Chiudi la finestra di {Chat}",{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("Chiudi la finestra di {Chat}",{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("Nascondi la finestra della {Chat}",{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("Non \u00e8 stato possibile recuperare la cronologia della chat"),'</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("Cancella cronologia {Chat} ",{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("Sei online.",{name:this.firstName});}else g=_tx("Non sei online.",{name:this.firstName});}else if(e){g=_tx("{name} \u00e8 online.",{name:this.firstName});}else g=_tx("{name} \u00e8 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("Oggi");}else if(c<b)return _tx("Ieri");}var d='';switch(a.getMonth()){case 0:d=_tx("gennaio");break;case 1:d=_tx("febbraio");break;case 2:d=_tx("marzo");break;case 3:d=_tx("aprile");break;case 4:d=_tx("maggio");break;case 5:d=_tx("giugno");break;case 6:d=_tx("luglio");break;case 7:d=_tx("agosto");break;case 8:d=_tx("settembre");break;case 9:d=_tx("ottobre");break;case 10:d=_tx("novembre");break;case 11:d=_tx("dicembre");break;}return _tx("{date} {month}",{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("Nuovo messaggio da {name}!",{name:c});}else document.title=_tx("Nuovo messaggio!");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("Inattivo");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("Si \u00e8 verificato un errore"),_tx("Non \u00e8 possibile avere due liste con lo stesso nome. Attribuisci un altro nome a questa lista."));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("modifica")+'</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("Passa offline"):_tx("Passa 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("Nessuno \u00e8 disponibile a chattare."),'</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("Non \u00e8 possibile trovare quell'amico connesso.")+'</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("Non pu\u00f2 caricare gli amici disponibili."));},_showLoading:function(){this._showError(_tx("Caricamento..."));},_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("Trascina le liste per riordinare.")),$N('input',{type:'button',className:'inputbutton',value:_tx("Riordinamento completato"),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("Per aggiungere un amico trascinalo qui")));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("Scrivi il nome di una lista"));var e=$N('div',{className:'new_list'},[$N('span',{},_tx("Crea una nuova lista:")),f]);var d=$N('div',{className:'text'},_tx("Mostra in chat le seguenti liste:"));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("Passa a 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("Riordina le liste"))]);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("Includi la chat nella finestra principale"):_tx("Apri chat in una finestra separata")))]);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("Attiva suono per i nuovi messaggi")},{name:'sticky_buddylist',label:_tx("Tieni aperta la finestra degli amici online")},{name:'compact_buddylist',label:_tx("Mostra solo i nomi degli amici online")}];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("Non \u00e8 stato possibile modificare l'impostazione"));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 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("Impossibile impostare lo stato della {Chat}",{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 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("Nessuna nuova notifica."));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("Nascondi tutto"),handler:e};var h={name:'report',label:_tx("Segnala come spam"),handler:g};var c={};copy_properties(c,Dialog.CANCEL);c.handler=b||bagofholding;new Dialog().setTitle(_tx("Vuoi nascondere tutte le notifiche da {application-name}?",{'application-name':a})).setBody(_tx("Cos\u00ec si nasconderanno tutte le notifiche di questa applicazione.")).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('inbox'),this._handleInboxMsg.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){this._updateInboxUnreadCount(a);var b=ge('fb_menu_inbox_dropdown');if(b&&c)b.setContent(HTML(c));},_updateInboxUnreadCount:function(a){if(this.navInbox&&a!=null)CounterDisplay.setCount('messages_unread',a);},_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));var e=this.alertList.alertsObj[b];if(e)Bootloader.loadComponents('live-timer',function(){LiveTimer.addTimeStamps(e);});},_handleInboxMsg:function(c,a){var b=a.obj;b&&this._updateInboxUnreadCount(b.unread);},_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\/blzdtt54tsocwg88.pkg.js"]); }