/*1306808209,176820662*/

if (window.CavalryLogger) { CavalryLogger.start_js(["d3IKB"]); }

var ChatUserInfos=window.ChatUserInfos||{};
var FriendLists=window.FriendLists||{get:function(a){var b=FriendLists._map;if(!b[a])b[a]=[];return b[a];},set:function(a,b){if(b===undefined)return;var c=FriendLists.get(a);c.length=0;c.push.apply(c,$A(b));},_map:{}};
var AvailableList=window.AvailableList||(function(){var b=5;var d=60000;var e='/ajax/chat/buddy_list.php';var c=5000;var a=.005;var zb=0;var zh=false;var t=0;var za=false;var y=null;var q=null;var j=null;var p=0;var i=null;var z={};var w={};var x={};var k=null;var r={'0':2,'1':1,'-1':0};var zc={0:-1,1:1,2:0};function n(){return Chat.isOnline()?(zh?y:q):null;}function g(zj,zn,zk,zm){if(zj==Env.user)return;switch(zn){case AvailableList.OFFLINE:case AvailableList.IDLE:case AvailableList.ACTIVE:break;default:return;}var zl=AvailableList.get(zj)!=zn;if(zk){w[zj]=zn;x[zj]=zm||(presence.getTime()+d);delete z[zj];}else z[zj]=zn;if(zl){zb++;if(!j)j=zd.defer();}}function s(zk,zl,zj){k({observer:presence.user,observee:zk,status:zl,latency:zj});}function zf(zj){i=zj;Arbiter.inform('buddylist/count-changed',zj);}function ze(zj){if(presence.isShutdown||!Chat.isOnline()){AvailableList._poller.stop();return;}p=new Date();za=true;zj.setHandler(v).setErrorHandler(u).setTransportErrorHandler(u).setOption('suppressErrorAlerts',true).setOption('retries',1).setData({user:Env.user,popped_out:presence.poppedOut,available_list:AvailableList.haveFullList?m():{},force_render:zh}).setURI(e).setAllowCrossPageTransition(true);}function v(zm){var zl=zm.getPayload();var zj=zl.buddy_list;if(!zj){u(zm);return;}presence.updateServerTime(zl.time);AvailableList.updateTime=presence.getTime();t=0;za=false;if(zj.forcedRender)AvailableList.haveFullList=true;if(zj.availableCount)zf(zj.availableCount);var zn=zj.userInfos;if(zn)copy_properties(ChatUserInfos,zn);var zk=zj.nowAvailableList;if(zj.wasAvailableIDs)zj.wasAvailableIDs.forEach(function(zo){if(!(zk&&(zo in zk))&&(z[zo]!=AvailableList.OFFLINE)&&((zo in w)&&(w[zo]==AvailableList.OFFLINE)))s(zo,AvailableList.OFFLINE,presence.getTime()+d-x[zo]);z[zo]=AvailableList.OFFLINE;});zk&&AvailableList.addLegacyAvailableList(zk);zi();Arbiter.inform('buddylist/fl-changed',{flMode:zj.flMode,flData:zj.flData});presenceCookieManager.store();}function u(zj){if(presence.checkMaintenanceError(zj))return;t++;za=false;if(t>=b){zf(0);Arbiter.inform('buddylist/update-error');}}function m(){var zj={};AvailableList.getAvailableIDs().forEach(function(zk){zj[zk]={i:AvailableList.isIdle(zk)?1:0};});return zj;}function zi(){if(AvailableList.haveFullList)Arbiter.inform('buddylist/updated');}function zd(){j=null;if(AvailableList.haveFullList)zf(AvailableList.getAvailableIDs().length);Arbiter.inform('buddylist/availability-changed');}function h(zj,zl){for(var zk in zj){var zn;var zm;if(zl){zn=r[zj[zk].ol];zm=zj[zk].exp;}else zn=zj[zk]?(zj[zk].i?AvailableList.IDLE:AvailableList.ACTIVE):0;g(zk,zn,zl,zm);zj[zk]&&zj[zk].fl&&FriendLists.set(zk,zj[zk].fl);}}function o(){zg();if(Chat.isOnline()){AvailableList.update();}else f();}function f(){AvailableList.haveFullList=false;z={};w={};x={};zd();}function zg(){AvailableList._poller&&AvailableList._poller.setTimePeriod(n());}function l(){var zj={};Chat.getActiveChats().forEach(function(zn){var zm=AvailableList.get(zn);if(zm)zj[zn]={i:zm==AvailableList.IDLE?1:0};});var zk={ac:i,ut:parseInt(AvailableList.updateTime*.001,10),ud:y*.001,lc:0};var zl=AvailableList.getLegacyOverlay();if(!is_empty(zl))zk.uo=zl;if(!is_empty(zj))zk.al=zj;return zk;}return {OFFLINE:0,IDLE:1,ACTIVE:2,haveFullList:false,init:function(zp,zl,zo,zn,zm,zj,zk){k=EagleEye.createLogger('presence-status',presence.sitevars.BUDDY_STATUS_LOG_FRAC||a);AvailableList.updateTime=zp;AvailableList.haveFullList=zl;AvailableList.addLegacyOverlay(zo);AvailableList.addLegacyAvailableList(zj);y=zn;q=zm;AvailableList._poller=new Poller(n(),ze);zf(zk);Arbiter.subscribe('presence/restarted',AvailableList.update);Arbiter.subscribe('chat/visibility-changed',o);Arbiter.subscribe('presence-cookie-manager/initialized',function(zq,zr){zr.register('bl',l);});if(AvailableList.haveFullList){p=new Date();}else if(zh)AvailableList.update();},get:function(zj){if(zj==Env.user)return AvailableList.ACTIVE;if(zj in w&&(presence.getTime()<x[zj]||!(zj in z)))return w[zj];return z[zj]||AvailableList.OFFLINE;},isReady:function(){return AvailableList.haveFullList;},set:function(zk,zl,zj){zj&&FriendLists.set(zk,$A(zj));g(zk,zl,true);window.presence&&presence.doSync();},update:function(){if(new Date()-p<c){!za&&zi.defer();return;}zh=true;zg();AvailableList._poller&&AvailableList._poller.requestNow();},getRev:function(){return zb;},isIdle:function(zj){return AvailableList.get(zj)==AvailableList.IDLE;},getCount:function(){return i;},getAvailableIDs:function(){var zj,zk=[];for(zj in z)if(AvailableList.get(zj))zk.push(zj);for(zj in w){if(zj in z)continue;if(AvailableList.get(zj))zk.push(zj);}return zk;},getLegacyOverlay:function(){var zk={};for(var zj in w)if(x[zj]>presence.getTime())zk[zj]={exp:x[zj],fl:FriendLists.get(zj),ol:zc[w[zj]]};return zk;},addLegacyOverlay:function(zj){h(zj,true);},addLegacyAvailableList:function(zj){h(zj,false);},getDebugInfo:function(zj){return {presence:z[zj],overlay:w[zj],overlayTime:x[zj]};}};})();
if(!window.Chat){var Chat={openTab:function(a,b,c){Chat._withComponent('chatDisplay',function(d){d.focusTab(a,true,b,b,c);});},loadTabFragile:function(b,c,a,d){Chat._withComponent('chatDisplay',function(e){e.loadTabFragile(b,c,a,d);});},openBuddyList:function(){Chat._withComponent('buddyListNub',function(a){a.show();});},closeBuddyList:function(){Chat._withComponent('buddyListNub',function(a){a.hide();});},toggleSidebar:function(){Chat._withComponent('sidebar',function(a){a.toggle();});},goOnline:function(a){Arbiter.subscribe('chat-options/initialized',function(event,b){if(Chat.isOnline()){a&&a();}else{if(a)var c=Arbiter.subscribe('chat/visibility-changed',function(){Arbiter.unsubscribe(c);a();});b.sendVisibility(true);}});},isOnline:function(){return window.chatOptions&&chatOptions.visibility;},squelchTab:function(a,b){Chat._withComponent('chatDisplay',function(c){b!==false&&c.unfocus(a,false);c.setSquelchedTab(a,true);});},unsquelchTab:function(a){Chat._withComponent('chatDisplay',function(b){b.setSquelchedTab(a,false);});},enterErrorMode:function(a){Chat._withComponent('buddyList',function(b){b.enterErrorMode(a);});},getActiveChats:function(){if(!window.chatDisplay)return [];return keys(chatDisplay.tabs);},isFeatureAvailable:function(a){return window.chatDisplay&&a in chatDisplay.gatedFeatures&&chatDisplay.gatedFeatures[a];},_componentInitEvents:{buddyList:'buddylist/initialized',chatDisplay:'chat-display/loaded',buddyListDisplay:'buddylist-display/initialized',buddyListNub:'buddylist-nub/initialized',sidebar:'sidebar/initialized'},_withComponent:function(b,a){Arbiter.subscribe(Chat._componentInitEvents[b],function(event,c){a(c);});}};Chat._withComponent("buddyList",function(a){Chat._buddyList=a;});copy_properties(Chat,{debugPrintUpdateOverlay:function(){Chat._withComponent('buddyList',function(a){a.debugPrintUpdateOverlay();});},updateUserInfo:function(a){Chat._buddyList&&Chat._buddyList.updateUserInfos(a);},setUserInfo:function(b,c,a){ChatUserInfos[b]=c;Chat._withComponent('buddyList',function(d){d.updateItemDisplay(b);a&&FriendLists.set(b,a);});}});}
var OrderedFriendsList=window.OrderedFriendsList||(function(){var a=[];var b={};return copy_properties(new Arbiter(),{init:function(c){a=c;a.forEach(function(e,d){b[e]=d;});this.inform('initialized',{},Arbiter.BEHAVIOR_PERSISTENT);},contains:function(c){return c in b;},compare:function(c,d){var g=OrderedFriendsList.getRank(c);var h=OrderedFriendsList.getRank(d);if(g!==h)return g-h;var e=((ChatUserInfos[c]||{}).name||'').toLowerCase();var f=((ChatUserInfos[d]||{}).name||'').toLowerCase();return e&&f?(e<f?-1:(e>f?1:0)):(e?-1:(f?1:0));},getList:function(){return $A(a);},getRank:function(c){return c in b?b[c]:a.length;}});})();
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;}};
Dcode=function(){var a,d={},b={_:'%',A:'%2',B:'000',C:'%7d',D:'%7b%22',E:'%2c%22',F:'%22%3a',G:'%2c%22ut%22%3a1',H:'%2c%22bls%22%3a',I:'%2c%22n%22%3a%22%',J:'%22%3a%7b%22i%22%3a0%7d',K:'%2c%22pt%22%3a0%2c%22vis%22%3a',L:'%2c%22ch%22%3a%7b%22h%22%3a%22',M:'%7b%22v%22%3a2%2c%22time%22%3a1',N:'.channel%22%2c%22sub%22%3a%5b',O:'%2c%22sb%22%3a1%2c%22t%22%3a%5b',P:'%2c%22ud%22%3a100%2c%22lc%22%3a0',Q:'%5d%2c%22f%22%3anull%2c%22uct%22%3a',R:'.channel%22%2c%22sub%22%3a%5b1%5d',S:'%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a',T:'%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a',U:'%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a',V:'%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a',W:'%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a',X:'%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1',Y:'%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a',Z:'%2c%22sb%22%3a1%2c%22t%22%3a%5b%5d%2c%22f%22%3anull%2c%22uct%22%3a0%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%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];}));}};}();
Dcode_deprecated=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(b,a){this.version=b;this.cookieName='presence';this.dictEncode=a;this.storers={};this.requireUserCookie=false;Arbiter.inform('presence-cookie-manager/initialized',this,Arbiter.BEHAVIOR_PERSISTENT);}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.stringify(b);if(this.dictEncode)c='E'+Dcode.encode(c);if(!this.requireUserCookie||presence.hasUserCookie(false))setCookie(this.cookieName,c,null);},clear:function(){clearCookie(this.cookieName);},_getCookie:function(){try{var data=getCookie(this.cookieName);if(this.lastD===data){return this.lastV;}else{this.lastD=data;this.lastV=null;}if(data&&data.charAt(0)=='E'){data=Dcode.decode(data.substring(1));}else if(data&&data.charAt(0)=='D')data=Dcode_deprecated.decode(data.substring(1));if(data){this.lastV=JSON.parse(data);return this.lastV;}}catch(a){}return null;},getSubCookie:function(b){var a=this._getCookie();if(!a)return null;return a[b];},setCheckUserCookie:function(a){this.requireUserCookie=a;}};
