/* TF2Lobby.com
 * Copyright 2010 Ryan "FLOOR_MASTER" Mannion. All rights reserved.
 * The contents of this file may not be used in any other context than
 * tf2lobby.com without permission
 */

$(document).ready(function(){window.main={translateClasses:{scout:"Scout",soldier:"Soldier",pyro:"Pyro",demo:"Demoman",heavy:"Heavy",engy:"Engineer",medic:"Medic",sniper:"Sniper",spy:"Spy",noclass:"Any Class"},authed:false,connected:false,synced:false,lastAccountId:0,lobbies:{},subs:{},users:{},pingIntervalSeconds:60,pingTimer:null,pongTimer:null,pongFails:0,maxPongFails:5,lastLobbyInfoRequest:0,subRequestLifetimeSeconds:300,steamFriends:{},pendingLobbyInfo:{},lobbyInfo:{},lobbyInfoScrollInit:false,showLobbyInfoInProgress:false,showingLobbyInfo:false,restoreNoticeTimer:null,restoreNoticeTimeout:7000,loadLight:new Image(16,16),lastChatMessage:null,lastChatTime:new Date(),chatThrottleMilliseconds:2500,infoListContainerHeight:205,chatAreaHeightOffset:0,chatAreaOffsetStep:100,changingLoungeNotice:false};var b=new Date();window.timeOffset=parseInt(b.getTime()/1000)-window.sTime;window.tooltip=new Tooltip();window.tooltip.setup($('div#signupDialog label[for="steamid"]'),'<div style="width: 300px">Your SteamID can be in the form <strong>STEAM_0:0:12345</strong> or a link to your Steam Community Profile, such as <strong>http://steamcommunity.com/id/FLOOR_MASTER</strong></div>');window.tooltip.setup($('div#signupDialog label[for="authKey"]'),'<div style="width: 300px">To verify that you own the Steam account above, please copy this code anywhere in your Steam Profile.<br/><br/>Click on this label to automatically open up your Edit Profile page in Steam.<br/><br/>You can delete the code after you successfully sign up.</div>').addClass("pointer").click(function(c){c.preventDefault();location.href="steam://url/SteamIDEditPage"});$('div#signupDialog input[name="authKey"]').focus(function(c){c.preventDefault();this.select()});window.main.loadLight.src="/img/loadLight.gif";$(".dialog").dialog({modal:true,autoOpen:false,open:function(c,d){$(".ui-dialog-titlebar-close").hide()},width:400});$("#mapDialog").dialog("option","width",550);$("#forgotPassword a").click(function(c){c.preventDefault();$("#loginDialog").dialog("close");$("#forgotpasswordDialog").dialog("open")});$(".dialogLink").click(function(d){d.preventDefault();var c="#"+$(this).attr("name")+"Dialog";$(c).dialog("open")});$('.dialogLink[name="createlobby"]').click(function(c){$("#addressContainer").hide();$("#rconPasswordContainer").hide()});$("form.popup").submit(onAjaxFormSubmit);$("#privateCheckbox").click(function(c){if($(this).attr("checked")=="yes"){$(this).attr("checked","no").attr("src","/img/check_off.png");$("#lobbyPasswordContainer").fadeOut();$('input[name="privateLobby"]').val(false)}else{$(this).attr("checked","yes").attr("src","/img/check_on.png");$("#lobbyPasswordContainer").fadeIn();$('input[name="privateLobby"]').val(true)}});$("#serverType").change(function(d){var c=$(this).val();if(c=="auto"){$("#addressContainer").fadeOut();$("#rconPasswordContainer").fadeOut()}else{if(c=="custom"){$("#addressContainer").fadeIn();$("#rconPasswordContainer").fadeIn()}}});$('.dialogLink[name="logout"]').click(onLogoutClicked);$("#chatForm").submit(onChatSubmit);$("#lobbyInfo").mouseover(function(c){if(window.main.restoreNoticeTimer!=null){clearTimeout(window.main.restoreNoticeTimer)}}).mouseout(function(c){if(window.main.restoreNoticeTimer!=null){clearTimeout(window.main.restoreNoticeTimer)}window.main.restoreNoticeTimer=setTimeout(restoreNotice,window.main.restoreNoticeTimeout)});$("#raiseChatArea").click(function(c){c.preventDefault();if(window.main.chatAreaHeightOffset-window.main.chatAreaOffsetStep>=0){adjustChatArea(0-window.main.chatAreaOffsetStep);window.main.chatAreaHeightOffset-=window.main.chatAreaOffsetStep;if(window.context.accountId>0){$.post("/ajax/persistent",{context:$.toJSON(window.context),key:"loungeChatHeight",value:window.main.chatAreaHeightOffset})}}});$("#lowerChatArea").click(function(c){c.preventDefault();adjustChatArea(window.main.chatAreaOffsetStep);window.main.chatAreaHeightOffset+=window.main.chatAreaOffsetStep;if(window.context.accountId>0){$.post("/ajax/persistent",{context:$.toJSON(window.context),key:"loungeChatHeight",value:window.main.chatAreaHeightOffset})}});if(window.steamFriends!=null){for(var a in window.steamFriends){window.main.steamFriends[window.steamFriends[a]]=true}}setLoungeNoticeText(window.loungeNotices,false);swfobject.embedSWF("/swf/lobbyClient.swf","mainClient","1","1","9.0.0",null,{host:window.config.client.host,port:window.config.client.port},{allowScriptAccess:"always"});showDialog("Connecting!",'Please wait while you are connected to the server.<br/><br/><span class="small">If this takes longer than 10 seconds, there may be a problem on our end. Please also check that you do not have Flash blocked.</span>',true)});function adjustLobbyArea(a){window.main.infoListContainerHeight+=a;$("#lobbies").height($("#lobbies").height()+a);$("#info").height($("#info").height()+a);$("#lobbyListContainer").height(window.main.infoListContainerHeight);$("#lobbyInfoListOuterContainer").height(window.main.infoListContainerHeight);$("#lobbyInfoListContainer").height($("#lobbyInfoListContainer").height()+a);$("#lobbyListContainer")[0].scrollUpdate();var b=$("#lobbyInfoListContainer")[0];if(b&&b.scrollUpdate){b.scrollUpdate()}}function adjustChatArea(b){var a=false;var c=$("#messageWindowContainer .contentwrapper")[0];if((c.offsetTop*-1)+5>=c.clientHeight-(($("#messageWindowContainer")[0].clientHeight-10)*1.5)){a=true}$("#messageWindowContainer").height($("#messageWindowContainer").height()+b);$("#users").height($("#users").height()+b);$("#userListContainer").height($("#userListContainer").height()+b);$("#messageWindowContainer")[0].scrollUpdate();$("#userListContainer")[0].scrollUpdate();if(a){scrollFlexToBottom("messageWindowContainer")}}function sbConnectedHandler(){if(window.context.accountId>0){var a=[{type:"checkRTKey",context:window.context,steamName:window.steamName,rtKey:window.rtKey}];sendRT(a)}else{var a=[{type:"getClientId",context:window.context}];sendRT(a)}window.main.connected=true;window.main.authed=false;window.main.synced=false}function sbDisconnectedHandler(){window.main.connected=false;window.main.authed=false;window.rtKey="";$("#disconnectWarning").fadeIn()}function sbIncomingHandler(sData){sData=decodeURIComponent(sData);var dataObj=eval("("+sData+")");if(dataObj!=null){sbProcessMessage(dataObj)}}function showYouTube(a){$("#youtubeContent").html('<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/'+a+'&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+a+'&hl=en&fs=1&autoplay=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>');$("#youtubeDialog").dialog("option","width",600).dialog("open")}function addChat(c,f){var a=$("#messageWindow")[0];var j=false;var e=$("#messageWindowContainer .contentwrapper")[0];if((f==null||f==false)&&(e.offsetTop*-1)+5>=e.clientHeight-(($("#messageWindowContainer")[0].clientHeight-10)*1.5)){j=true}var h=new Date();if(c.posted!=null){h.setTime((c.posted+window.timeOffset)*1000)}var g=(h.getHours()<10?"0":"")+h.getHours()+(h.getMinutes()<10?":0":":")+h.getMinutes()+(h.getSeconds()<10?":0":":")+h.getSeconds();if(c.notice==null){var i=c.msg.htmlEncode();i=i.replace(/(youtube.com\/watch\?v=([^\s&]+)\S*)/g,'$1 <img src="/img/tubeIcon.png" style="cursor: pointer" onClick="showYouTube(\'$2\')"/>');i=i.replace(/(^|\s)((?:http:\/\/)?(?:www\.)?tf2lobby.com\/lobby\?id=\S+)/g,'$1<a href="$2" target="_blank" class="joinLobby">Join Lobby</a>');i=i.replace(/(^|\s)((?:https?:\/\/|www\.|steam:\/\/)\S+)\.?/g,'$1<a href="$2" target="_blank" class="gray">$2</a>');var b=(c.color==null?"":' style="color: '+c.color+'"');$("#messageWindow").append('<div class="chat"><div class="time">'+g+'</div><div class="text"><a href="/profile?id='+c.accountId+'" target="_blank" class="chatName"'+b+">"+c.accountName.htmlEncode()+":</a> "+i+"</div></div>")}else{$("#messageWindow").append('<div class="chat"><div class="time">'+g+'</div><div class="text">'+c.notice+"</div></div>")}$("#messageWindowContainer")[0].scrollUpdate();if(j&&(f==null||f==false)){scrollFlexToBottom("messageWindowContainer")}}function scrollFlexToBottom(d){var a=$("#"+d)[0];var c=$("#"+d+" .contentwrapper")[0];var b=c.clientHeight-a.clientHeight+10;if(b>0){a.contentScroll(false,b+"px",false)}}function checkLobbyCount(){var b=0;for(var a in window.main.lobbies){if(window.main.lobbies[a].isFull==false){b++}}if(b==0){if($("#lobbyList li.none").length==0){$('<li class="none"><a href="#">No Lobbies Open</a></li>').click(function(c){c.preventDefault();$("#createlobbyDialog").dialog("open")}).hide().appendTo("#lobbyList").fadeIn()}}else{$("#lobbyList li.none").fadeOut("normal",function(){$(this).remove()})}}function sbProcessMessage(c){if(c.debug!=null){return}if(window.main.synced==false){if(c.type=="authed"){window.main.clientId=c.clientId;window.main.authed=true;$.post("/ajax/syncmain",{context:$.toJSON(window.context),clientId:window.main.clientId})}else{if(c.type=="clientId"){window.main.clientId=c.clientId;$.post("/ajax/syncmain",{context:$.toJSON(window.context),clientId:window.main.clientId})}else{if(c.type=="sync"){window.main.synced=true;$("#userList > li").fadeOut().remove();window.main.users={};for(var f in c.currentUsers){var a=new User(f,c.currentUsers[f]);window.main.users[f]=a}$("#onlineCount").html(Object.size(window.main.users)+" ");$("#userListContainer")[0].scrollUpdate();for(var d=c.chat.length-1;d>=0;d--){addChat(c.chat[d],true)}scrollFlexToBottom("messageWindowContainer");for(var d in c.lobbies){var e=new Lobby(c.lobbies[d])}if(c.steamFriends!=null){for(var d in c.steamFriends){window.main.steamFriends[c.steamFriends[d]]=true}}window.main.pingTimer=setTimeout(ping,window.main.pingIntervalSeconds*1000);checkLobbyCount();if(window.preferences.loungeChatHeight!=null){window.main.chatAreaHeightOffset=window.preferences.loungeChatHeight;adjustChatArea(window.preferences.loungeChatHeight)}$("#messageDialog").dialog("close")}else{}}}return}if(c.type=="newLobby"){if(window.main.lobbies[c.lobbyId]==null){var e=new Lobby(c)}else{}}else{if(c.type=="closeLobby"){if(window.main.lobbies[c.lobbyId]!=null){window.main.lobbies[c.lobbyId].close()}}else{if(c.type=="updateLobby"){var e=window.main.lobbies[c.lobbyId];e.update(c);if(window.main.lastLobbyInfoRequest==e.id){window.main.lastLobbyInfoRequest=e.id;e.showLobbyInfo()}}else{if(c.type=="chat"){c.accountName=window.main.users[c.accountId].name;addChat(c)}else{if(c.type=="authed"){if(window.main.authed==false){window.main.clientId=c.clientId;window.main.authed=true}else{}}else{if(c.type=="leave"){if(window.main.users[c.accountId]!=null){window.main.users[c.accountId].leave();$("#onlineCount").html(Object.size(window.main.users)+" ");$("#userListContainer")[0].scrollUpdate()}}else{if(c.type=="enter"){if(window.main.users[c.accountId]==null){var a=new User(c.accountId,c);window.main.users[c.accountId]=a;$("#onlineCount").html(Object.size(window.main.users)+" ");$("#userListContainer")[0].scrollUpdate()}}else{if(c.type=="pong"){window.main.pongFails=0;if(window.main.pongTimer!=null){clearTimeout(window.main.pongTimer);window.main.pongTimer=null}window.main.pingTimer=setTimeout(ping,window.main.pingIntervalSeconds*1000)}else{if(c.type=="accountMessage"||c.type=="clientMessage"){if(c.subType=="statusDialog"){showDialog(c.title,c.msg,true)}}else{if(c.type=="subRequested"){var b=new Sub(c);$("#lobbyListContainer")[0].contentScroll(false,"0px",false)}else{if(c.type=="subFilled"){if(window.main.subs[c.subId]!=null){window.main.subs[c.subId].close()}}else{if(c.type=="notice"){if(c.subType=="loungeNotice"){restoreNotice();setLoungeNoticeText(c.lines,true)}}else{}}}}}}}}}}}}}function setLoungeNoticeText(a,b){var d=$("ul#noticeTextList").empty();if(b){window.main.changingLoungeNotice=true;d.hide()}for(var c in a){if(a[c].length>0){$("<li></li>").html(a[c]).appendTo(d)}}if(b){d.show("pulsate");setTimeout(function(){window.main.changingLoungeNotice=false},4000)}}function sendRT(a){$("#mainClient").flash(function(){this.send($.toJSON(a))})}function dbg(e){var c=new Date();var a=c.getHours()+(c.getMinutes()<10?":0":":")+c.getMinutes()+(c.getSeconds()<10?":0":":")+c.getSeconds();$("#messageWindow").append('<div class="chat">'+a+": "+e+"</div>");var b=$("#messageWindow")[0];b.scrollTop=b.scrollHeight}function onChatSubmit(b){b.preventDefault();var a=new Date(window.main.lastChatTime.getTime()+window.main.chatThrottleMilliseconds);var c=new Date();if(window.context.accountId==0){showDialog("Login First!","Please login before chatting")}else{if(c>a){window.main.lastChatTime=c;var d=$("#chatMsg").val();if(d.length){if(d==window.main.lastChatMessage){showDialog("Spam?","Your last chat message was identical. Spamming the Lounge chat will likely lead to being muted.")}else{$.post("/ajax/mainchat",{context:$.toJSON(window.context),msg:d});window.main.lastChatMessage=d}}$("#chatMsg").val("")}}}function showDialog(c,b,a){$("#messageTitle").html(c);$("#messageContent").html(b);$("#messageDialog").dialog("open");if(a==null||a==false){$("#messageDialog > .popup > .buttons").show();$("#messageDialog").dialog("option","closeOnEscape",true)}else{$("#messageDialog > .popup > .buttons").hide();$("#messageDialog").dialog("option","closeOnEscape",false)}}function status(){$("#mainClient").flash(function(){this.send($.toJSON([{type:"status"}]))})}function ping(){window.main.pingTimer=null;$("#mainClient").flash(function(){this.send($.toJSON([{type:"ping",accountId:window.context.accountId}]))});if(window.main.pongTimer!=null){clearTimeout(window.main.pongTimer);window.main.pongTimer=null}window.main.pongTimer=setTimeout(pongTimeout,5000)}function pongTimeout(){window.main.pongTimer=null;window.main.pongFails++;if(window.main.pongFails>=window.main.maxPongFails){$("#mainClient").flash(function(){this.disconnect()});sbDisconnectedHandler()}else{ping()}}function onLogoutClicked(a){a.preventDefault();$.post("ajax/logout",{},function(c){$('.dialogLink[name="login"]').fadeIn();$('.dialogLink[name="signup"]').fadeIn();$('.dialogLink[name="createlobby"]').fadeOut();$('.dialogLink[name="logout"]').fadeOut();$("#lobbyList > li > a").removeClass("active");$("#playerName").html("Join");$("#profileButton").fadeOut();window.main.lastAccountId=window.context.accountId;window.context.accountId=0;window.main.authed=false;window.rtKey="";window.main.steamFriends={};var b=[{type:"logout",context:window.context}];sendRT(b)},"json")}function onAjaxFormSubmit(c){c.preventDefault();var b=$(this).attr("name");var a="#"+b+"Dialog";$(a).dialog("close");if(b=="createlobby"){showDialog("Please Wait...","Creating lobby and configuring server",true)}else{if(b=="signup"){showDialog("Please Wait...","Creating account",true)}else{if(b=="login"){showDialog("Please Wait...","Please wait while your Steam name and avatar are fetched from the Steam Community",true)}}}$.post("ajax/"+b,{data:$(this).serialize()},function(f){$("#messageDialog").dialog("close");if(f.hasOwnProperty("message")&&f.message.length){showDialog(f.messageTitle,f.message);if(f.error){$("#messageDialog").bind("dialogclose",function(h,i){$(a).dialog("open");$("#messageDialog").unbind("dialogclose")})}}if(f.action=="login"&&!f.error){$('.dialogLink[name="login"]').fadeOut();$('.dialogLink[name="logout"]').html("Logout ").fadeIn();$('.dialogLink[name="signup"]').fadeOut();$('.dialogLink[name="createlobby"]').fadeIn();$("#profileButton").attr("href","/profile?id="+f.accountId).fadeIn();$("#playerName").html('<span class="emphasizeName">'+f.steamName.htmlEncode()+"</span>, join");window.context.accountId=f.accountId;window.rtKey=f.rtKey;window.steamName=f.steamName;window.main.steamFriends={};for(var d in f.steamFriends){window.main.steamFriends[f.steamFriends[d]]=true}for(var g in window.main.users){window.main.users[g].moveToFriends()}var e=[{type:"checkRTKey",context:window.context,steamName:window.steamName,rtKey:window.rtKey}];sendRT(e)}if((f.action=="createlobby"||f.action=="loginlobby")&&!f.error){window.open("/lobby?id="+f.lobbyId+(f.password==null?"":"&pw="+f.password))}},"json")}function User(c,a){this.id=c;this.name=a.steamName;this.fid=a.fid;this.color=a.color;var b=this.fid;this._userNode=$('<li class="user">'+this.name.htmlEncode()+"</li>").attr("accountId",this.id).click(function(d){d.preventDefault();window.open("/profile?id="+c)}).css("cursor","pointer");if(this.color){this._userNode.css("color",this.color)}if(this.fid in window.main.steamFriends||this.id==window.context.accountId){this.insertSorted("userListFriends")}else{this.insertSorted("userList")}}User.prototype.moveToFriends=function(){if(this.fid in window.main.steamFriends||this.id==window.context.accountId){this.insertSorted("userListFriends")}};User.prototype.insertSorted=function(g){var e=$("#"+g+" li");if(e.length==0){this._userNode.hide().appendTo($("#"+g)).fadeIn()}else{var f=0;var b=0;var c=e.length-1;var d=this.name.toLowerCase();while(f<c){b=Math.floor((f+c)/2);var a=e[b].innerHTML.toLowerCase();if(d>=a){f=b+1}else{if(d<a){c=b-1}else{break}}}b=Math.max(0,Math.floor((f+c)/2));var a=e[b].innerHTML.toLowerCase();if(d<a){this._userNode.hide().insertBefore(e[b]).fadeIn()}else{this._userNode.hide().insertAfter(e[b]).fadeIn()}}return this};User.prototype.leave=function(){this._userNode.fadeOut("normal",function(){$(this).remove()});if(window.main.lastAccountId!=0&&this.id==window.main.lastAccountId){$("#userListFriends > li").each(function(a){window.main.users[$(this).attr("accountId")].insertSorted("userList")})}delete window.main.users[this.id]};function LobbyInfo(a){this._baseAvatarUrl="http://media.steampowered.com/steamcommunity/public/images/avatars/";this._baseSteamUrl="http://steamcommunity.com/profiles/";this.accountId=a;this._listNode=$("<li></li>").attr("accountId",this.accountId);this._avatarNode=$('<img src="/img/loadLight.gif"/>').appendTo(this._listNode);this._nameNode=$('<div class="steamName">Loading...</div>').appendTo(this._listNode);this._clearNode=$('<div class="clear"></div>').appendTo(this._listNode);this.node=this._listNode;return this}LobbyInfo.prototype.rebind=function(){this._listNode.unbind("click").click(function(a){window.open("/profile?id="+$(this).attr("accountId"))})};LobbyInfo.prototype.setData=function(a){this.avatar=a.avatar;this.color=a.color;this.fid=a.fid;this.name=a.name;this._listNode.css("cursor","pointer");this.rebind();this._avatarNode.attr("src",this._baseAvatarUrl+this.avatar);var b=this.name;if(b.length>20){b=b.substr(0,17)+"..."}this._nameNode.html(b.htmlEncode());return this};function Sub(b){this.id=b.subId;this["class"]=b["class"];this.region=b.region;this.team=b.team;this.map=b.map;var c=this;this._expireTimer=setTimeout(function(){c.close()},window.main.subRequestLifetimeSeconds*1000);var a=(this["class"]=="noclass"?"player":window.main.translateClasses[this["class"]]);var d="A ";switch(a[0].toLowerCase()){case"a":case"e":case"i":case"o":case"u":d="An "}this._listNode=$("<li></li>");this._closeNode=$('<a href="#" subId="'+this.id+'" class="close">X</a>').appendTo(this._listNode).click(Sub.prototype.onCloseClick).addClass(this.team+"Sub");this._linkNode=$('<a href="#" subId="'+this.id+'"></a>').addClass(this.team+"Sub").appendTo(this._listNode).click(Sub.prototype.onClick).html(d+a+" for "+this.map+" is needed! Click to join.");if(this.region!="Unknown"){this._regionNode=$('<img src="/img/flags/'+this.region+'.png" class="region"/>').prependTo(this._linkNode)}this._listNode.hide().prependTo("#lobbyList").fadeIn("normal",function(){$("#lobbyListContainer")[0].scrollUpdate()});window.main.subs[this.id]=this}Sub.prototype.onCloseClick=function(a){a.preventDefault();var b=$(this).attr("subId");if(window.main.subs[b]==null){return}window.main.subs[b].close()};Sub.prototype.onClick=function(b){b.preventDefault();var c=$(this).attr("subId");if(window.main.subs[c]==null){return}var a=window.main.subs[c];if(window.context.accountId==0){showDialog("Login First!","Please login before accepting a sub request")}else{$.post("/ajax/sub",{context:$.toJSON(window.context),subId:a.id},function(e){if(e.error){showDialog("Could not join!","Thanks for volunteering, but the spot was already filled")}else{var f="steam://connect/"+e.sub.serverAddress+"/"+e.sub.serverPassword;$("#subbingAddress").html(e.sub.serverAddress);$("#subbingPassword").html(e.sub.serverPassword);var d=window.main.translateClasses[e.sub["class"]];$("#subbingTeamClass").html(e.sub.team+'<img src="/img/class/'+e.sub["class"]+'.png"/>'+d).addClass(e.sub.team+"Fg");$("#subbingRetryButton").unbind("click").click(function(g){g.preventDefault();location.href=f});setTimeout(function(){location.href=f},2500);$("#subbingDialog").dialog("open")}},"json")}};Sub.prototype.close=function(){if(this._expireTimer!=null){clearTimeout(this._expireTimer);this._expireTimer=null}this._listNode.fadeOut("normal",function(){$(this).remove();checkLobbyCount();$("#lobbyListContainer")[0].scrollUpdate()});delete window.main.subs[this.id]};function Lobby(c){this.id=c.lobbyId;this.name=c.lobbyName;this.mapPreview=c.mapPreview;this.mapName=c.mapName;this.isPrivate=(c.isPrivate==0?false:true);this.inLobby=c.inLobby;this.numPlayers=Object.size(this.inLobby);this.userInLobby=false;this.maxPlayers=c.maxPlayers;this.isFull=false;this.region=c.region;this.longitude=c.longitude;this.latitude=c.latitude;this.game_type=c.game_type;this.class_limits=c.class_limits;this.voice_options=c.voice_options;this.damage=c.damage;this._listNode=$("<li></li>").hide();this._linkNode=$('<a href="lobby?id='+this.id+'" class="lobbyLink" lobbyId="'+this.id+'"></a>').appendTo(this._listNode).attr("target","_blank").click(Lobby.prototype.onClick).mouseover(Lobby.prototype.onMouseOver).mouseout(Lobby.prototype.onMouseOut);this._mapPreviewNode=$('<img src="/img/maps/'+this.mapPreview+'" width="80"/>').appendTo(this._linkNode);this._lobbyNameNode=$('<span class="title">'+this.name.htmlEncode()+"</span>").appendTo(this._linkNode);if(this.region!=null&&this.region!=false&&this.region!="Unknown"){this._regionNode=$('<img src="/img/flags/'+this.region+'.png" class="region"/>').appendTo(this._linkNode);this._listNode.attr("region",this.region)}else{this._listNode.attr("region","Unknown")}this._mapNameNode=$('<span class="map">'+this.mapName+"</span>").appendTo(this._linkNode);this._numPlayersNode=$('<span class="players">'+this.numPlayers+" / "+this.maxPlayers+"</span>").appendTo(this._linkNode);this._privateNode=$('<img src="/img/lock.png" alt="[Private Lobby]" class="private"/>');$('<div class="clear"></div>').appendTo(this._linkNode);if(this.isPrivate){this._privateNode.prependTo(this._numPlayersNode);this._listNode.appendTo("#lobbyList")}else{if(this.region==window.myRegion){var b=($('#lobbyList > li[region="'+window.myRegion+'"]:not(:has(.private))').length>0);if(b){$('#lobbyList > li[region="'+window.myRegion+'"]:not(:has(.private)):last').after(this._listNode)}else{this._listNode.prependTo("#lobbyList")}}else{var a=($("#lobbyList > li:has(.private)").length>0);if(a){$("#lobbyList > li:has(.private):first").before(this._listNode)}else{this._listNode.appendTo("#lobbyList")}}}window.main.lobbies[this.id]=this;this.updateActive();return this}function reset(){window.main.lastLobbyInfoRequest=0;window.main.accountInfo={}}function restoreNotice(){$("#lobbyInfo").fadeOut("normal",function(){$("#notice").fadeIn();window.main.showingLobbyInfo=false;window.main.lastLobbyInfoRequest=0})}Lobby.prototype.onMouseOut=function(a){if(window.main.restoreNoticeTimer!=null){clearTimeout(window.main.restoreNoticeTimer)}window.main.restoreNoticeTimer=setTimeout(restoreNotice,window.main.restoreNoticeTimeout)};Lobby.prototype.onMouseOver=function(a){var c=$(this).attr("lobbyId");var b=window.main.lobbies[c];if(window.main.changingLoungeNotice==true){return}if(window.main.lastLobbyInfoRequest!=b.id&&window.main.showLobbyInfoInProgress==false){window.main.lastLobbyInfoRequest=b.id;b.showLobbyInfo()}};Lobby.prototype.showLobbyInfo=function(){if(window.main.restoreNoticeTimer!=null){clearTimeout(window.main.restoreNoticeTimer)}if(window.main.showingLobbyInfo==false){window.main.showingLobbyInfo=true;var a=this;$("#notice").hide();$("#lobbyInfo").show();if(window.main.lobbyInfoScrollInit==false){window.main.lobbyInfoScrollInit=true;CSBfleXcroll("lobbyInfoListContainer")}a.generateLobbyInfo()}else{this.generateLobbyInfo()}};Lobby.prototype.showGMapsImage=function(){if(this.latitude==null||this.longitude==null){return}var a='<img src="http://maps.google.com/maps/api/staticmap?center='+this.latitude+","+this.longitude+"&markers="+this.latitude+","+this.longitude+"&zoom=5&size=500x300&sensor=false&key="+window.gApiKey+'"/>';$("#mapDialog #mapImageContainer").html(a);$("#mapDialog #mapInfo").html(this.name);$("#mapDialog").dialog("open")};Lobby.prototype.generateLobbyInfo=function(){window.main.showLobbyInfoInProgress=true;$("#lobbyInfoList li").unbind("click");$('#lobbyInfoListContainer div.config[type="region"]').unbind("click");$("#lobbyInfoMain").empty();var d=$("<div></div>").appendTo("#lobbyInfoMain");d.append('<div class="config">Game Type: <span class="configValue">'+window.translate.lobbyOptions.game_type[this.game_type]+'</span></div><div class="config">Class Limits: <span class="configValue">'+window.translate.lobbyOptions.class_limits[this.class_limits]+'</span></div><div class="config">Voice Options: <span class="configValue">'+window.translate.lobbyOptions.voice_options[this.voice_options]+'</span></div><div class="config">Damage: <span class="configValue">'+window.translate.lobbyOptions.damage[this.damage]+"</span></div>");var a=$('<div class="config" type="region">Region: <span class="configValue">'+(this.region==null||this.region=="Unknown"||this.region==false?"Unknown":'<img src="/img/flags/'+this.region+'.png" alt="['+this.region+']"/>')+"</span></div>").appendTo(d);if(this.latitude!=null&&this.longitude!=null){a.append("<span>&nbsp;Large Map</span>").attr("lobbyId",this.id).addClass("pointer").click(function(i){i.preventDefault();var j=window.main.lobbies[$(this).attr("lobbyId")];j.showGMapsImage()});var c='<img src="http://maps.google.com/maps/api/staticmap?center='+this.latitude+","+this.longitude+"&markers="+this.latitude+","+this.longitude+"&zoom=4&size=170x70&sensor=false&key="+window.gApiKey+'" class="gMap"/>';$(c).addClass("pointer").attr("lobbyId",this.id).click(function(i){i.preventDefault();var j=window.main.lobbies[$(this).attr("lobbyId")];j.showGMapsImage()}).appendTo(d)}d.after('<div class="playerHeader">'+this.numPlayers+" Player"+(this.numPlayers==1?"":"s")+"</div>");$("#lobbyInfoList li").css("opacity",1).remove();var g=new Array();for(var b in this.inLobby){var h=this.inLobby[b];if(window.main.lobbyInfo[h]==null){var f=new LobbyInfo(h);window.main.pendingLobbyInfo[h]=f;g.push(h);f.node.appendTo("#lobbyInfoList")}else{var f=window.main.lobbyInfo[h];f.node.appendTo("#lobbyInfoList");f.rebind()}}if(g.length>0){$.ajax({type:"POST",url:"/ajax/accountinfo",dataType:"json",data:{context:$.toJSON(window.context),accountIds:$.toJSON(g)},success:function(i){for(var k in window.main.pendingLobbyInfo){if(k in i.accountInfo){var j=window.main.pendingLobbyInfo[k];j.setData(i.accountInfo[k]);window.main.lobbyInfo[k]=j}else{}}$("#lobbyInfoListContainer")[0].scrollUpdate();window.main.pendingLobbyInfo={};window.main.showLobbyInfoInProgress=false},error:function(i,k,j){$("#lobbyInfoListContainer")[0].scrollUpdate();window.main.pendingLobbyInfo={};window.main.showLobbyInfoInProgress=false}})}else{window.main.showLobbyInfoInProgress=false}var e=$("#lobbyInfoListContainer")[0];if(e&&e.scrollUpdate){e.scrollUpdate()}};Lobby.prototype.onClick=function(c){var e=$(this).attr("lobbyId");var b=window.main.lobbies[e].isPrivate;var d=window.main.lobbies[e];var a=(d.numPlayers>=d.maxPlayers&&d.userInLobby==false);if(window.context.accountId==0){c.preventDefault();showDialog("Login First!","Please login before joining a lobby")}else{if(a){c.preventDefault();showDialog("Lobby Full!","Please wait for a spot to open or create a new lobby")}else{if(b&&window.authedLobbies[e]!=true){c.preventDefault();$("#loginlobbyForm > #lobbyId").val(e);$("#loginlobbyDialog").dialog("open");$('#loginlobbyForm :input[name="lobbyPassword"]').focus()}}}};Lobby.prototype.close=function(){this._listNode.fadeOut("normal",function(){$(this).remove();checkLobbyCount();$("#lobbyListContainer")[0].scrollUpdate()});delete window.main.lobbies[this.id]};Lobby.prototype.update=function(a){if(a.inLobby!=null&&a.inLobby instanceof Array){this.inLobby=a.inLobby;this.updateActive()}if(a.option!=null&&a.value!=null&&window.translate.lobbyOptions[a.option]!=null&&window.translate.lobbyOptions[a.option][a.value]!=null){this[a.option]=a.value}};Lobby.prototype.updateActive=function(){this.numPlayers=Object.size(this.inLobby);this._numPlayersNode.html(this.numPlayers+" / "+this.maxPlayers);if(this.isPrivate){this._privateNode.prependTo(this._numPlayersNode)}if(window.context.accountId==0){this._linkNode.removeClass("active");this.userInLobby=false}else{var b=false;for(var a in this.inLobby){if(this.inLobby[a]==window.context.accountId){this._linkNode.addClass("active");this.userInLobby=true;b=true}}if(b==false){this._linkNode.removeClass("active");this.userInLobby=false}}if(this.numPlayers>=this.maxPlayers&&this.userInLobby==false&&false){this._listNode.fadeOut();this.isFull=true}else{this._listNode.fadeIn();this.isFull=false}checkLobbyCount();$("#lobbyListContainer")[0].scrollUpdate()};