(function(B){var A={setPosition:function(){},getPosition:function(){},setSize:function(){},getSize:function(){},setClientSize:function(){},getClientSize:function(){},addWidget:function(){},enable:function(){},disable:function(){},onSkinChange:function(){}};B.chess.registerWidget({name:"tab",$interface:A},{},true);B.widget("ui.tab",B.implement(A,{$:null,$$:{},setPosition:function(C){B.sharedInterface.setPosition.apply(this,[C])
},getPosition:function(){return B.sharedInterface.getPosition.apply(this,[])},setSize:function(C){B.sharedInterface.setSize.apply(this,[C])},getSize:function(){return B.sharedInterface.getSize.apply(this,[])},setClientSize:function(D){if((typeof D.width!="number")&&(typeof D.height!="number")){return}var C=this.getClientSize();if(typeof D.width=="number"){C.width=D.width}if(typeof D.height=="number"){C.height=D.height
}C.width+=this.$$.offset.left+this.$$.offset.right;C.height+=this.$$.offset.top+this.$$.offset.bottom;this.$.css(C);this.update({newsize:C})},getClientSize:function(){return{width:this.$.width()-this.$$.offset.left-this.$$.offset.right,height:this.$.height()-this.$$.offset.top-this.$$.offset.bottom}},addWidget:function(D,C){this.$$.controls[D.attr("instanceid")]=D.appendTo(this.$.find(">.chess-tab-content"));
if((C!=false)){D.show()}try{if(C!=false&&!D[0]._ui.options.visible){D.hide()}if(D[0]._ui.options.register==true){this.$[0][D.attr("instanceid")]=D;D[0].parent=this.$[0]}}catch(E){}},enable:function(){B.sharedInterface.enable.apply(this,[]);B.each(this.$$.controls,function(){this.enable()})},disable:function(){B.sharedInterface.disable.apply(this,[]);B.each(this.$$.controls,function(){this.disable()
})},onSkinChange:function(){this.$$.offset=B.chess.getSkinMetrics("tab","offset");this.$$.buttonSize=B.chess.getSkinMetrics("tab","buttonSize");this.update()},init:function(){this.$=this.element;this.$$=this.element[0]._$$={};this.$$.controls={};var C=this.$._ui=this;var D=this.options;this.$$.offset=B.chess.getSkinMetrics("tab","offset");this.$$.buttonSize=B.chess.getSkinMetrics("tab","buttonSize");
this.$.addClass("chess-control chess-tab selected-online").css({left:D.left,top:D.top,width:D.width,height:D.height}).append(B.chess.createBackgroundElements().find(".tl").remove().end().append('<div class="btns"><div/></div>')).append('<div class="chess-tab-content" /><div class="chess-tab-online">online <span>(0)</span></div><div class="chess-tab-offline">offline <span>(0)</span></div>').find(".c").remove().end().find(".chess-tab-online").click(function(){if(C.$.is(".selected-online")){return
}C.$.removeClass("selected-offline").addClass("selected-online");C.$.triggerHandler("tab-tabswitch",["online"],C.options.tabswitch)}).end().find(".chess-tab-offline").click(function(){if(C.$.is(".selected-offline")){return}C.$.removeClass("selected-online").addClass("selected-offline");C.$.triggerHandler("tab-tabswitch",["offline"],C.options.tabswitch)});if(this.options.widgets){B.each(this.options.widgets,function(){C.addWidget(this)
})}this.update();C.$.triggerHandler("tab-tabswitch",["online"],C.options.tabswitch);this.$.triggerHandler("tab-init",[this],this.options.init)},update:function(D){var G=D||{};var E=G.newsize||this.getSize();if(E.width<=0||E.height<=0){return}var I=G.offset||this.$$.offset;var H=E.width-I.left-I.right;var C=E.height-I.top-I.bottom-this.$$.buttonSize.height;(G.element||this.$).find(">.chess-control-background .bs,>.chess-tab-content").width(H).end().find(">.chess-control-background .ts").width(H-this.$$.buttonSize.width).end().find(">.chess-control-background .ls,>.chess-control-background .rs,>.chess-tab-content").height(C);
var F={width:H,height:C};this.$.triggerHandler("tab-resize",[{tab:E,client:F}],this.options.resize)}}));B.ui.tab.getter="getPosition getSize getClientSize";B.ui.tab.defaults={left:0,top:0,width:200,height:250,visible:true,resize:function(){},tabswitch:function(){},init:function(){}}})(jQuery);(function(A){A.chess.registerWidget({name:"chat_friends",$interface:IList},{},true);A.widget("ui.chat_friends",A.implement(IList,{$:null,$$:{},setPosition:function(B){A.sharedInterface.setPosition.apply(this,[B])
},getPosition:function(){return A.sharedInterface.getPosition.apply(this,[])},setSize:function(B){A.sharedInterface.setSize.apply(this,[B])},getSize:function(){return A.sharedInterface.getSize.apply(this)},addItem:function(B){this.$$.list.addItem(B)},addItems:function(B){this.$$.list.addItems(B)},removeItem:function(B){this.$$.list.removeItem(B)},clear:function(){this.$$.list.clear()},getItem:function(B){return this.$$.list.getItem(B)
},setItem:function(B,C){this.$$.list.setItem(B,C)},getCount:function(){return this.$$.list.getCount()},setSelectedIndex:function(B,C){this.$$.list.setSelectedIndex(B,C)},getSelectedIndex:function(){return this.$$.list.getSelectedIndex()},scrollIntoView:function(B){this.$$.list.scrollIntoView()},enable:function(){this.$$.list.enable()},disable:function(){this.$$.list.disable()},onSkinChange:function(){this.$$.list.onSkinChange()
},init:function(){this.$=this.element;this.$$=this.element[0]._$$={};var B=this.$[0]._ui=this;var C=function(D,E){D.attr("id",E.id).find(".avatar").html(A.chess.transPNG(E.avatar,30,24)).end().find(".ranking span").html(E.ranking).end().find(".games span").text(E.games).end().find(".name").html(E.name)};this.$$.list=A.chess.list(A.copy(this.options,{left:0,top:0,width:198,height:255,name:this.options.name?this.options.name+".$$.list":this.options.name,adapter:{selectable:false,itemHeight:38,baseHTML:'<div class="chat_friends-item"><div class="bgd"/><div class="avatar"/><div class="name"/><div class="ranking">'+LANG.SEARCH_RANKING+' <span/></div><div class="games"><div/><span>0</span></div><div class="hover"/></div>',insert:C,update:C},resize:function(D){B.$.width(D.size.width).height(D.size.height);
B.$.triggerHandler("chat_friends-resize",[{size:D.size}],B.options.resize)},click:function(E,D){B.$.triggerHandler("chat_friends-click",[E,D],B.options.click)},mouseenter:function(D){B.$.triggerHandler("chat_friends-mouseenter",[D],B.options.mouseenter)},mouseleave:function(D){B.$.triggerHandler("chat_friends-mouseleave",[D],B.options.mouseleave)},itemmouseenter:function(D,E){B.$.find(".hover:eq("+D+")").show();
B.$.triggerHandler("chat_friends-itemmouseenter",[D,E],B.options.itemmouseenter)},itemmouseleave:function(D,E){B.$.find(".hover:eq("+D+")").hide();B.$.triggerHandler("chat_friends-itemmouseleave",[D,E],B.options.itemmouseleave)},itemclick:function(E){var D=B.$$.list.getItem(E);B.$.triggerHandler("chat_friends-itemclick",[E,D],B.options.itemclick)}})).appendTo(this.$.addClass("chess-control chess-chat_friends").css({left:this.options.left,top:this.options.top})).show()
},update:function(B){var D=B||{};var C=D.newsize||this.getSize();if(C.width<=0||C.height<=0){return}this.$$.list.setSize(C)}}));A.ui.chat_friends.getter="getPosition getSize getItem getCount getSelectedIndex";A.ui.chat_friends.defaults={left:0,top:0,width:84,height:24,enabled:true,visible:true,items:[],resize:function(){},click:function(){},mouseenter:function(){},mouseleave:function(){},itemmouseenter:function(){},itemmouseleave:function(){},itemclick:function(){}}
})(jQuery);(function(B){var A={setPosition:function(){},getPosition:function(){},setSize:function(){},getSize:function(){},setClientSize:function(){},getClientSize:function(){},addWidget:function(){},enable:function(){},disable:function(){},onSkinChange:function(){},setUserData:function(){}};B.chess.registerWidget({name:"buttonmenu",$interface:A},{},true);B.widget("ui.buttonmenu",B.implement(A,{$:null,$$:{},setPosition:function(C){B.sharedInterface.setPosition.apply(this,[C])
},getPosition:function(){return B.sharedInterface.getPosition.apply(this,[])},setSize:function(C){B.sharedInterface.setSize.apply(this,[C])},getSize:function(){return B.sharedInterface.getSize.apply(this,[])},setClientSize:function(D){if((typeof D.width!="number")&&(typeof D.height!="number")){return}var C=this.getClientSize();if(typeof D.width=="number"){C.width=D.width}if(typeof D.height=="number"){C.height=D.height
}C.width+=this.$$.offset.left+this.$$.offset.right;C.height+=this.$$.offset.top+this.$$.offset.bottom;this.$.css(C);this.update({newsize:C})},getClientSize:function(){return{width:this.$.width()-this.$$.offset.left-this.$$.offset.right,height:this.$.height()-this.$$.offset.top-this.$$.offset.bottom}},addWidget:function(D,C){this.$$.controls[D.attr("instanceid")]=D.appendTo(this.$.find(">.chess-buttonmenu-content"));
if((C!=false)){D.show()}try{if(C!=false&&!D[0]._ui.options.visible){D.hide()}if(D[0]._ui.options.register==true){this.$[0][D.attr("instanceid")]=D;D[0].parent=this.$[0]}}catch(E){}},enable:function(){B.sharedInterface.enable.apply(this,[]);B.each(this.$$.controls,function(){this.enable()})},disable:function(){B.sharedInterface.disable.apply(this,[]);B.each(this.$$.controls,function(){this.disable()
})},onSkinChange:function(){this.$$.offset=B.chess.getSkinMetrics("buttonmenu","offset");this.update()},setUserData:function(C){this.$$.user=C;this.$$.lblName.setText(C.name);this.$$.btnSpectate[0?"enable":"disable"]()},init:function(){this.$=this.element;this.$$=this.element[0]._$$={};this.$$.controls={};var C=this.$._ui=this;C.$$.id=0;var D=this.options;this.$$.offset=B.chess.getSkinMetrics("buttonmenu","offset");
this.$.addClass("chess-control chess-buttonmenu").css({left:D.left,top:D.top,width:D.width,height:D.height,"z-index":10000}).append(B.chess.createBackgroundElements()).append('<div class="chess-buttonmenu-content" />').hover(function(){C.$.triggerHandler("buttonmenu-mouseenter",[{element:this}],C.options.mouseenter)},function(){C.$.triggerHandler("buttonmenu-mouseleave",[{element:this}],C.options.mouseleave)
});C.addWidget(C.$$.btnChat=B.chess.button({left:0,top:24,width:81,height:22,caption:"Chat",click:function(){C.$.triggerHandler("buttonmenu-chat",[C.$$.user],C.options.chat)}}));C.addWidget(C.$$.btnInvite=B.chess.button({left:87,top:24,width:81,height:22,caption:"Play",click:function(){C.$.triggerHandler("buttonmenu-invite",[C.$$.user],C.options.invite)}}));C.addWidget(C.$$.btnProfile=B.chess.button({left:0,top:52,width:81,height:22,caption:"Profile",click:function(){C.$.triggerHandler("buttonmenu-profile",[C.$$.user],C.options.profile)
}}));C.addWidget(C.$$.btnSpectate=B.chess.button({left:87,top:52,width:81,height:22,caption:"Spectate",click:function(){C.$.triggerHandler("buttonmenu-spectate",[C.$$.user],C.options.spectate)}}));C.addWidget(C.$$.lblName=B.chess.label({left:1,top:2,width:165,height:23,color:"#fff",fontSize:"14px"}));this.update();this.$.triggerHandler("buttonmenu-init",[this],this.options.init)},update:function(D){var G=D||{};
var E=G.newsize||this.getSize();if(E.width<=0||E.height<=0){return}var I=G.offset||this.$$.offset;var H=E.width-I.left-I.right;var C=E.height-I.top-I.bottom;(G.element||this.$).find(">.chess-control-background .ts,>.chess-control-background .bs,>.chess-control-background .c,>.chess-buttonmenu-content").width(H).end().find(">.chess-control-background .ls,>.chess-control-background .rs,>.chess-control-background .c,>.chess-buttonmenu-content").height(C).end();
var F={width:H,height:C};this.$.triggerHandler("buttonmenu-resize",[{buttonmenu:E,client:F}],this.options.resize)}}));B.ui.buttonmenu.getter="getPosition getSize getClientSize";B.ui.buttonmenu.defaults={left:0,top:0,width:184,height:90,visible:true,resize:function(){},init:function(){},mouseenter:function(){},mouseleave:function(){},chat:function(){},invite:function(){},profile:function(){},spectate:function(){}}
})(jQuery);(function(A){var B={setPosition:function(){},getPosition:function(){},setSize:function(){},getSize:function(){},say:function(){},came_online:function(){},went_offline:function(){},info:function(){},update:function(){}};A.chess.registerWidget({name:"conversation",$interface:B},{},true);A.widget("ui.conversation",A.implement(B,{$:null,$$:{},setPosition:function(C){A.sharedInterface.setPosition.apply(this,[C])
},getPosition:function(){return A.sharedInterface.getPosition.apply(this,[])},setSize:function(C){A.sharedInterface.setSize.apply(this,[C])},getSize:function(){return A.sharedInterface.getSize.apply(this,[])},say:function(E,G,K,H){var I="",F="";if(this.$$.lastid!=E){var C=this.$$.lastid!=-1?' style="margin-top:2px"':"";this.$$.lastid=E;var D=E==User.id?User.short_name:Friends.get(E).short_name;var J=E==User.id?" me":"";
I='<div class="separator'+J+'"'+C+'><div class="bgrd"/><div class="from">'+D+'</div><div class="time">'+A.date("H:i A",G)+"</div></div>"}if(H&&!this.$$.offline){this.$$.offline=true;F='<div class="info"><div class="bgrd"/>'+Friends.get(H).short_name+" is offline, message will be delivered next time "+(Friends.get(H).gender?"she":"he")+" signs in.</div>"}this.$$.textbox.setText(this.$$.textbox.getText()+F+I+'<div class="message">'+App.filterString(K)+"</div>")
},came_online:function(C){if(!this.$$.offline){return}this.$$.offline=false;this.info(C+" signed in.",A.chess.timestamp())},went_offline:function(C){if(this.$$.offline){return}this.info(C+" signed out.",A.chess.timestamp())},info:function(E,D){var C='<div class="info"><div class="bgrd"/>'+E;if(D){C+='<div class="time">'+A.date("H:i A",D)+"</div>"}this.$$.textbox.setText(this.$$.textbox.getText()+C+"</div>")
},init:function(){this.$=this.element;this.$$=this.element[0]._$$={lastid:-1,offline:false};var C=this.$[0]._ui=this;A.ui.enableSelection((this.$$.textbox=A.chess.textbox(A.extend({},this.options,{left:0,top:0})).appendTo(this.$.addClass("chess-control chess-conversation").css({left:this.options.left,top:this.options.top,width:this.options.width,height:this.options.height})).show()).find(".chess-textbox-content"));
this.$$.textbox.scrollToEnd(true)},update:function(C){var E=C||{};var D=E.newsize||this.getSize();if(D.width<=0||D.height<=0){return}this.$$.textbox.setSize(D)}}));A.ui.conversation.getter="getPosition getSize";A.ui.conversation.defaults={left:0,width:200,height:250,text:"",enabled:true,visible:true,color:A.chess.getSkinMetrics("textbox","color"),fontSize:A.chess.getSkinMetrics("textbox","fontSize"),lineHeight:A.chess.getSkinMetrics("textbox","lineHeight"),padding:A.chess.getSkinMetrics("textbox","padding"),resize:function(){},change:function(){},mouseenter:function(){},mouseleave:function(){},mousedown:function(){}}
})(jQuery);(function(B){var A={setPosition:function(){},getPosition:function(){},setSize:function(){},getSize:function(){},add:function(){},remove:function(){},markRead:function(){},markAllRead:function(){},update:function(){}};B.chess.registerWidget({name:"notifications",$interface:A},{},true);B.widget("ui.notifications",B.implement(A,{$:null,$$:{},setPosition:function(C){B.sharedInterface.setPosition.apply(this,[C])
},getPosition:function(){return B.sharedInterface.getPosition.apply(this,[])},setSize:function(C){B.sharedInterface.setSize.apply(this,[C])},getSize:function(){return B.sharedInterface.getSize.apply(this,[])},add:function(F,E,D,G){var C;(G||function(){})(this.$$.textbox.find(".chess-textbox-text").prepend('<div class="separator'+(this.$$.count++&1?" odd":"")+'"><div class="bgrd"/><div class="title">'+F+'</div><div class="time">'+B.date("D, H:i A",D)+'</div></div><div class="item _'+(C=this.$$.count)+'" style="margin-bottom:'+(this.$$.count>1?3:0)+'px">'+E+"</div>").find(".item:eq(0)"));
this.$$.textbox.update();Footbar.updateUnreadedNoties(++Notifications.unreaded);return C},remove:function(C){},markRead:function(C){this.$$.textbox.find(".item:eq("+C+")").addClass("readed").css("opacity",0.5).prepend('<div class="bgrd"/>')},markAllRead:function(){this.$$.textbox.find(".item:not(.readed)").each(function(){B(this).addClass("readed").css("opacity",0.5).prepend('<div class="bgrd"/>')})
},init:function(){this.$=this.element;this.$$=this.element[0]._$$={count:0};var C=this.$[0]._ui=this;B.ui.enableSelection((this.$$.textbox=B.chess.textbox(B.extend({},this.options,{left:0,top:0})).appendTo(this.$.addClass("chess-control chess-notifications").css({left:this.options.left,top:this.options.top,width:this.options.width,height:this.options.height})).show()).find(".chess-textbox-content"));
this.$$.textbox.scrollToEnd(false)},update:function(C){var E=C||{};var D=E.newsize||this.getSize();if(D.width<=0||D.height<=0){return}this.$$.textbox.setSize(D)}}));B.ui.notifications.getter="getPosition getSize add";B.ui.notifications.defaults={left:0,width:200,height:250,text:"",enabled:true,visible:true,color:B.chess.getSkinMetrics("textbox","color"),fontSize:B.chess.getSkinMetrics("textbox","fontSize"),lineHeight:B.chess.getSkinMetrics("textbox","lineHeight"),padding:B.chess.getSkinMetrics("textbox","padding"),resize:function(){},change:function(){},mouseenter:function(){},mouseleave:function(){},mousedown:function(){}}
})(jQuery);(function(A){A.chess.registerWidget({name:"quickplaylist",$interface:IList},{},true);A.widget("ui.quickplaylist",A.implement(IList,{$:null,setPosition:function(B){A.sharedInterface.setPosition.apply(this,[B])},getPosition:function(){return A.sharedInterface.getPosition.apply(this,[])},setSize:function(B){A.sharedInterface.setSize.apply(this,[B])},getSize:function(){return A.sharedInterface.getSize.apply(this)
},addItem:function(B){this.$$.list.addItem(B)},addItems:function(B){this.$$.list.addItems(B)},removeItem:function(B){this.$$.list.removeItem(arguments)},clear:function(){this.$$.list.clear()},getItem:function(B){return this.$$.list.getItem(B)},setItem:function(B,C){this.$$.list.setItem(B,C)},getCount:function(){return this.$$.list.getCount()},setSelectedIndex:function(B,C){this.$$.list.setSelectedIndex(B,C)
},getSelectedIndex:function(){return this.$$.list.getSelectedIndex()},scrollIntoView:function(B){this.$$.list.scrollIntoView()},enable:function(){this.$$.list.enable()},disable:function(){this.$$.list.disable()},onSkinChange:function(){this.$$.list.onSkinChange()},init:function(){this.$=this.element;this.$$=this.element[0]._$$={};var B=this.$[0]._ui=this;var C=function(E,F){if(!F.avatar.length){F.avatar=App.defaults.thumb_url
}else{if(!F.avatar.match(/-thumb\.png$/i)){F.avatar=F.avatar.substr(0,F.avatar.length-4)+"-thumb.png"}}E.find(".avatar").html(A.chess.transPNG(F.avatar,30,24)).end().find(".ranking span").html(F.ranking).end().find(".name").html(F.name);var D=F;A.chess.button({parent:E,top:9,right:6,width:51,height:18,caption:LANG.BTN_PLAY,fontSize:"11px",click:function(){B.$.triggerHandler("quickplaylist-play",[D],B.options.play)
}}).show()};this.$$.list=A.chess.list(A.extend({},this.options,{left:0,top:0,name:this.options.name?this.options.name+".$$.list":this.options.name,adapter:{selectable:false,itemHeight:38,baseHTML:'<div class="chess-quickplay-item"><div class="bgdr"/><div class="avatar"/><div class="name"/><div class="ranking">'+LANG.SEARCH_RANKING+"<span></span></div></div>",insert:C,update:C},resize:function(D){B.$.width(D.size.width).height(D.size.height);
B.$.triggerHandler("quickplaylist-resize",[{size:D.size}],B.options.resize)},click:function(E,D){B.$.triggerHandler("quickplaylist-click",[E,D],B.options.click)},mouseenter:function(D){B.$.triggerHandler("quickplaylist-mouseenter",[D],B.options.mouseenter)},mouseleave:function(D){B.$.triggerHandler("quickplaylist-mouseleave",[D],B.options.mouseleave)},itemmouseenter:function(D){B.$.find(".hover:eq("+D+")").show();
B.$.triggerHandler("quickplaylist-itemmouseenter",[D],B.options.itemmouseenter)},itemmouseleave:function(D){B.$.find(".hover:eq("+D+")").hide();B.$.triggerHandler("quickplaylist-itemmouseleave",[D],B.options.itemmouseleave)},itemclick:function(E){var D=B.$$.list.getItem(E);B.$.triggerHandler("quickplaylist-itemclick",[E,D],B.options.itemclick)}})).appendTo(this.$.addClass("chess-control chess-friend-list").css({left:this.options.left,top:this.options.top})).show();
this.$$.list.find(".chess-list-mousetrap").remove()},update:function(B){var D=B||{};var C=D.newsize||this.getSize();if(C.width<=0||C.height<=0){return}this.$$.list.setSize(C)}}));A.ui.quickplaylist.getter="getPosition getSize getItem getCount getSelectedIndex";A.ui.quickplaylist.defaults={left:0,top:0,width:84,height:24,enabled:true,visible:true,items:[],resize:function(){},click:function(){},play:function(){},mouseenter:function(){},mouseleave:function(){},itemmouseenter:function(){},itemmouseleave:function(){},itemclick:function(){}}
})(jQuery);Global.Notifications={lastNoty:0,lastNotyPerm:0,list:null,unreaded:0,mark_as_read:{},markAsRead:function(B,A){if(B in this.mark_as_read){this.mark_as_read[B](A)}},user_on:function(B,A){Friends.came_online(A.user_id)},user_off:function(B,A){Friends.went_offline(A.user_id)},chat_req:function(B,A){Chat.joinSession(A.user_id,A.chat_id);App.broadcast_addChat(A.chat_id,A.user_id)},quick_game_req:function(B,A){Notifications.game_req(B,A,true)
},game_req:function(F,C,E){var A,D=C,B=F;if((A=Friends.get(D.user_id,E?C.name:false)).id==D.user_id){Notifications.list[0]._ui.add("Game request",E?'<a href="javascript:User.viewProfile('+D.user_id+')">'+A.short_name+"</a>"+LANG.USER_WANTS_QUICK_PLAY:'<a href="javascript:User.viewProfile('+D.user_id+')">'+A.short_name+"</a>"+LANG.USER_WANTS_GAME,C.timestamp,function(H){var I,G,K;H.append(I=$("<div/>").css({width:140,height:25,position:"relative"}));
function J(M,L){$.chess.destroy(G);$.chess.destroy(K);I.html(M).css({padding:"0 4px",color:"#777","font-size":"11px","letter-spacing":"1px","line-height":"25px"});if(L){App.broadcast_removeNotification(B,M);delete Notifications.mark_as_read[B]}}Notifications.mark_as_read[B]=function(L){J(L);delete Notifications.mark_as_read[B]};G=$.chess.button({parent:I,left:3,top:3,width:46,height:18,caption:LANG.BTN_ACCEPT,fontSize:"10px",click:function(){var M,L;
$.chess.showOverlay();$get("startgame.opponent").setText(A.name);$get("startgame.color").setText(M=["white","black"][(D.color=="white")*1]);$get("startgame.duration").setText((D.duration/60)+" "+LANG.WND_START_NEW_GAME_MINUTES);L={id:D.game_id,server:D.server_id,color:M,opponent_army:D.figures,duration:D.duration,owner:false,last_move:0,my_move:-1,opponent:A,quick_play:E};App.windows.StartGame.data("gameData",L).opponentArmy(D.figures).selectArmy(User.favorite_army,true).data("callback",{accept:function(N){J("<em>"+LANG.INVITATION_ACCEPTED+"</em>",true);
if($("#board").length==0){App.redirect("/dashboard.php?act="+App.broadcast_action("join_game",N))}else{Game.joinGame(N,E)}},deny:function(){Game.rejectGame(D);J("<em>"+LANG.INVITATION_ACCEPTED+"</em>",true)}}).show()}}).show();K=$.chess.button({parent:I,left:56,top:3,width:46,height:18,caption:LANG.BTN_DENY,fontSize:"10px",click:function(){Game.rejectGame(D);J("<em>"+LANG.INVITATION_ACCEPTED+"</em>",true)
}}).show()});if(!App.windows.NotifyBox.is(":visible")){App.windows.NotifyBox.fadeIn(100)}}},offline_msg:function(D,C){var B,A=D;if((B=Friends.get(C.user_id)).id==C.user_id){Notifications.list[0]._ui.add(LANG.OFFLINE_MESSAGE_NOTIFICATION_TITLE,'<a href="javascript:User.viewProfile('+C.user_id+')">'+B.name+"</a>",C.timestamp,function(F){var G,E;F.append(G=$("<div/>").css({width:140,height:25,position:"relative"}));
function H(I){$.chess.destroy(E);G.html("").css({padding:"0 4px",color:"#777","font-size":"11px","letter-spacing":"1px","line-height":"25px"});if(I){App.broadcast_removeNotification(A,"");delete Notifications.mark_as_read[A]}}Notifications.mark_as_read[A]=function(){H();App.broadcast_removeNotification(A,"");delete Notifications.mark_as_read[A]};E=$.chess.button({parent:G,left:3,top:3,width:80,height:18,caption:LANG.BTN_VIEW_MESSAGE,fontSize:"10px",click:function(){E.disable();
App.request({page:"offline_message.php",data:{sender:B.id},success:function(I){if(I.status=="OK"&&I.data.length){Chatbar.openChat(B.id);var J;if((J=Chatbar.chatbox.find('.chess-conversation[instanceid="'+B.id+'!conv"]')).length){J[0]._ui.info(LANG.OFFLINE_MESSAGES_SENT_TO_YOU);$.each(I.data,function(){J[0]._ui.say(this.sender,this.timestamp,this.data)})}H(true);App.request({page:"comm.php",data:{cmd:"notif_delete",notif_id:C.msg_id}})
}},complete:function(){try{E.enable()}catch(I){}}})}}).show()})}},friend_req:function(C,B){var A=C;Notifications.list[0]._ui.add(LANG.FRIEND_REQUEST_NOTIFICATION_TITLE,LANG.FRIEND_REQUEST_NOTIFICATION_TEXT.replace("%user_link%",'<a href="javascript:User.viewProfile('+B.user_id+')">'+B.name+"</a>").replace("%user%",B.name.split(/\s/)[0]),B.timestamp,function(E){var F,D,H;E.append(F=$("<div/>").css({width:140,height:25,position:"relative"}));
function G(K,I,J){$.chess.destroy(D);$.chess.destroy(H);F.html(K).css({padding:"0 4px",color:"#777","font-size":"11px","letter-spacing":"1px","line-height":"25px"});if(I){App.request({page:"comm.php",data:{cmd:"notif_delete",notif_id:I}})}if(J){App.broadcast_removeNotification(A,K);delete Notifications.mark_as_read[A]}}Notifications.mark_as_read[A]=function(I){G(I);App.broadcast_removeNotification(A,I);
delete Notifications.mark_as_read[A]};D=$.chess.button({parent:F,left:3,top:3,width:46,height:18,caption:LANG.BTN_ACCEPT,fontSize:"10px",click:function(){App.request({page:"friends.php",data:{cmd:"confirm",req_id:B.req_id},success:function(I){if(I.status=="OK"){App.request({page:"user/info.php",data:{additional_info:true,id:B.user_id},success:function(J){if(J.status=="OK"){Friends.add(J.data)}}});G("<em>"+LANG.REQUEST_ACCEPTED+"</em>",B.msg_id,true)
}}})}}).show();H=$.chess.button({parent:F,left:56,top:3,width:46,height:18,caption:LANG.BTN_DENY,fontSize:"10px",click:function(){App.request({page:"friends.php",data:{cmd:"reject",req_id:B.req_id},success:function(I){if(I.status=="OK"){G("<em>"+LANG.REQUEST_REJECTED+"</em>",B.msg_id,true)}}})}}).show()});if(!App.windows.NotifyBox.is(":visible")){App.windows.NotifyBox.fadeIn(100)}},friend_accepted:function(D,C){var B=C,A=D;
Notifications.list[0]._ui.add(LANG.FRIEND_REQUEST_NOTIFICATION_TITLE,LANG.FRIEND_REQUEST_ACCEPTED.replace("%user%",'<a href="javascript:User.viewProfile('+B.user_id+')">'+B.name),B.timestamp,function(E){App.request({page:"user/info.php",data:{id:B.user_id,additional_info:true},success:function(F){if(F.status=="OK"){Friends.add(F.data);App.request({page:"comm.php",data:{cmd:"notif_delete",notif_id:B.msg_id}})
}}})})},friend_blocked:function(B,A){App.request({page:"comm.php",data:{cmd:"notif_delete",notif_id:A.msg_id}});Friends.remove(A.user_id)},notice:function(B,A){},warnning:function(B,A){},create:function(){if(!("NotifyBox" in App.windows)){App.windows.NotifyBox=$.chess.window({small:true,parent:"#footer",right:20,top:-304,width:230,height:300,resizable:true,resizableOptions:{minHeight:250,minWidth:230,maxWidth:300},disableHandle:"e,s,ne,se,sw",caption:LANG.BTN_NOTIFICATIONS,resize:function(A){Notifications.list.setSize(A.client)
},widgets:[Notifications.list=$.chess.notifications({left:0,top:0})]}).hide();$.chess.button({parent:App.windows.NotifyBox.find(".chess-window-caption"),right:0,top:5,width:16,height:16,caption:'<div class="xbutton"><div/></div>',click:function(){$get("footbar.notifications").click()}}).show()}}};Global.User={id:0,name:"",short_name:"",favorite_army:0,classic_pieces:false,ranking:1200,avatar:App.defaults.avatar_url,viewProfile:function(C,A){var B="/user/profile.php?id="+(C||this.id);
A||!(Game.running.length+Game.waiting.length)?location.href=B:window.open(B)},sendOfflineMessage:function(A,B,C){App.request({page:"offline_message.php",data:{msg:B,user_id:A},success:C})},startGame:function(B,C,D){if(!B){return}var A;if((A=Friends.get(B,C)).id==B){$.chess.showOverlay();$get("newgame.white").setValue(true);$get("newgame.duration").setSelectedIndex(3);$get("newgame.opponent").setText(A.name);
App.windows.NewGame.data("user",A).data("quick_play",D||false).selectArmy(User.favorite_army).show()}},sendFriendRequest:function(A,C,B){App.request({page:"friends.php",data:{cmd:"add",user_id:A},success:function(D){if(D.status=="OK"){C()}else{B(D.data)}}})},blockFriend:function(A){App.request({page:"friends.php",data:{cmd:"block",user_id:A}})}};Global.Chat={sessions:{},getChatList:function(){var B={},A=0;
$.each(this.sessions,function(C){if(C.length){A++;B["id_"+this.id]={off:this.offset,"with":this.user_id}}});return A?B:undefined},sessionExists:function(B,A){var C=false;$.each(this.sessions,function(){if(this.user_id==B){A=this.id;return !(C=true)}});return C},getSession:function(A){if(!A){return false}var B={session:null,key:""};if((A.constructor==String)&&(A.substr(0,3)=="id_")){A=A.substr(3)}if(("id_"+A) in this.sessions){B.session=this.sessions[B.key="id_"+A];
return B}for(var C in this.sessions){if(this.sessions[C].id==A){B.session=this.sessions[B.key=C];return B}}return false},newSession:function(B,D,C){var E=C||function(){},A;if(this.sessionExists(B,A)){this.sendMessageToUser(B,D);E(A);return}if(Global.Bots&&("id_"+B in Bots)){this.sendMessageToUser(B,D);E(-Bots["id_"+B]);return}Chatbar.sending.show();App.request({page:"comm.php",repeat:3,data:{cmd:"chat_invite",chat_init_with:B,chat_msg:D},success:function(F){if(F.status=="OK"){var H="id_"+F.data.response;
Chat.sessions[H]={offset:0,id:F.data.response,user:Friends.get(B).name.split(/\s/)[0],user_id:B,open:false};App.broadcast_addChat(F.data.response,B);E(F.data.response);Chatbar.sending.hide()}else{if(F.data=="USER_OFF"){Friends.went_offline(B);var G;if((G=Chatbar.chatbox.find('.chess-conversation[instanceid="'+B+'!conv"]')).length){G[0]._ui.say(User.id,$.chess.timestamp(),D,B)}User.sendOfflineMessage(B,D,function(){Chatbar.sending.hide()
});return}}}})},joinSession:function(B,A,C){var D;if((D=this.getSession(A))&&this.sessions[D.key]){this.sessions[D.key].id=A;return}Chat.sessions["id_"+A]={offset:0,id:A,user:Friends.get(B).name.split(/\s/)[0],user_id:B,open:false};Chatbar.openChat(B,A,C)},closeSession:function(A,B){var C;console.log("closeSession",arguments);if(C=this.getSession(A)){if(!B){App.request({page:"comm.php",data:{cmd:"chat_close",chat_id:C.session.id}})
}console.log("key =",C.key);App.broadcast_removeChat(C.session.id);delete this.sessions[C.key]}},message:function(A,C,E,H,F){var G,D;console.log("Chat.message called",arguments);if(G=this.getSession(A)){console.log("session, chatid, key = ",[G,A,G.key]);if(C*1>G.session.offset){this.sessions[G.key].offset=C*1}Chatbar.openChat(G.session.user_id,G.session.id);var B=$get(G.session.user_id+"!conv");B[0]._ui.say(E,F,H)
}},sendMessageToUser:function(A,E){console.log("Chat.sendMessageToUser called",arguments);if(Global.Bots&&("id_"+A in Bots)){var B=$get(A+"!conv");B[0]._ui.say(User.id,$.chess.timestamp(),E);var D=LANG.BOT_MESSAGES;B[0]._ui.say(A,$.chess.timestamp(),D[Math.floor(Math.random()*D.length)]);return}for(var C in this.sessions){if(C.length&&(this.sessions[C].user_id==A)){return Chat.sendMessage(C.substr(3),E,true)
}}this.newSession(A,E)},sendMessage:function(C,F,E){console.log("Chat.sendMessage called",arguments);var D,B;if(D=(E?this.sessions["id_"+C]:this.getSession(C).session)){Chatbar.sending.show();if(!Friends.get(B=D.user_id).online){User.sendOfflineMessage(D.user_id,F,function(){Chatbar.sending.hide()});return}var A="id_"+C;App.request({page:"comm.php",repeat:3,data:{cmd:"chat_send",chat_id:D.id,chat_msg:F},success:function(G){if(G.status=="ERR"){if(G.data=="NO_CHAT"){App.request({page:"comm.php",data:{cmd:"chat_invite",chat_init_with:B,chat_msg:F},success:function(I){if(I.status=="ERR"){if(I.data=="USER_OFF"){Friends.went_offline(B);
var H;if((H=Chatbar.chatbox.find('.chess-conversation[instanceid="'+B+'!conv"]')).length){H[0]._ui.say(User.id,$.chess.timestamp(),F,B)}User.sendOfflineMessage(B,F,function(){Chatbar.sending.hide()});return}}else{Chat.sessions[A].id=G.data.response*1}Chatbar.sending.hide()}})}}else{Chatbar.sending.hide()}}})}},command:function(A,C,D,F,E){var G;if(G=this.getSession(A)){console.log("Chat.command called:",arguments,G);
switch(F){case"timeout":Friends.went_offline(G.session.user_id);case"closed":var B;if(F=="closed"&&(B=Chatbar.chatbox.find('.chess-conversation[instanceid="'+G.session.user_id+'!conv"]')).length){B[0]._ui.info(LANG.CHAT_CLOSED,$.chess.timestamp())}this.closeSession(G.key,true)}}}};Global.FriendList={online:null,offline:null,create:function(A){if(!("FriendList" in App.windows)){var H=$.extend({left:20,top:-304},A||{}),F,E,C,D;
var G=$.chess.buttonmenu({parent:"#footer",mouseenter:function(){clearTimeout(B)},mouseleave:function(){G.hide()},chat:function(I){Chatbar.openChat(I.id)},invite:function(I){User.startGame(I.id)},profile:function(I){User.viewProfile(I.id)},spectate:function(I){}}).hide(),B;App.windows.FriendList=$.chess.window({small:true,parent:"#footer",left:H.left,top:H.top,width:230,height:300,resizable:true,resizableOptions:{minHeight:250,minWidth:230,maxWidth:300},disableHandle:"w,s,nw,se,sw",showCaption:false,resize:function(I){$get("friendlist.tab").setSize(I.client)
},widgets:[$.chess.tab({name:"friendlist.tab",resize:function(I){FriendList.online.setSize(I.client);FriendList.offline.setSize(I.client)},tabswitch:function(J){var I=J=="online";FriendList.online[I?"show":"hide"]().mousemove();FriendList.offline[I?"hide":"show"]().mousemove()},widgets:[FriendList.online=$.chess.chat_friends({name:"friendlist.online",itemmouseenter:function(I,J){clearTimeout(B);B=setTimeout(function(){var M=App.windows.FriendList,K=M.width()+25,N=J-M.height()+25,L=$get("friendlist.online").getItem(I);
if(N>-G.height()){N=-G.height()-3}G.css({left:K,top:N}).setUserData(L).show()},G.is(":visible")?0:400)},itemmouseleave:function(){if(!G.is(":visible")){clearTimeout(B)}else{B=setTimeout(function(){G.hide()},500)}},itemclick:function(J,I){Chatbar.openChat(I.id);clearInterval(B);G.hide()}}).show(),FriendList.offline=$.chess.chat_friends({name:"friendlist.offline",itemclick:function(J,I){$.chess.showOverlay();
F.jq().html($.chess.transPNG(I.avatar,30,24));E.find(".name").text(I.short_name).end().find(".to").text(I.gender?"her":"him").end().find(".g").text(I.gender?"she":"he");C.setText("").enable().find("input").css("font-style","normal");D.enable();App.windows.OfflineMessage.setCaption(I.name).data("user_id",I.id).appear()}}).hide()]}),$.chess.button({right:0,top:-3,width:16,height:16,caption:'<div class="xbutton"><div/></div>',click:function(){App.windows.FriendList.hide()
}})]}).hide().css("overflow","visible").find(".chess-window-content").css("overflow","visible").end();App.windows.NewGame=$.chess.window({parent:"#ontop-container",width:344,height:363,left:324,top:95,caption:LANG.WND_START_NEW_GAME_TITLE,ontop:true,draggable:true,widgets:[$.chess.frame({left:0,top:0,width:320,height:311,widgets:[$.chess.label({left:8,top:7,width:78,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_NEW_GAME_OPPONENT}),$.chess.label({name:"newgame.opponent",left:110,top:7,width:216,height:25,lineHeight:"22px",fontSize:"14px",color:"#fff"}),$.chess.label({left:8,top:42,width:78,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_NEW_GAME_COLOR}),$.chess.radio({group:"newgame.color",name:"newgame.white",left:110,top:40,text:LANG.WND_START_NEW_GAME_WHITE,lineHeight:"20px",fontSize:"13px",value:true}),$.chess.radio({group:"newgame.color",name:"newgame.black",left:180,top:40,text:LANG.WND_START_NEW_GAME_BLACK,lineHeight:"20px",fontSize:"13px"}),$.chess.label({left:8,top:77,width:78,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_NEW_GAME_DURATION}),$.chess.selectbox({name:"newgame.duration",left:110,top:75,width:50,items:[10,15,20,30,45,60]}),$.chess.label({left:170,top:77,width:78,height:25,lineHeight:"22px",fontSize:"12px",text:LANG.WND_START_NEW_GAME_MINUTES}),$.chess.label({left:8,top:112,width:78,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_NEW_GAME_ARMY}),$.chess.label({name:"newgame.armyname",left:110,top:112,width:216,height:25,lineHeight:"22px",fontSize:"14px",color:"#fff"}),$.chess.layer({left:8,top:145,width:94,height:52,html:'<div class="chess-army"><div class="army0"/></div>',css:{cursor:"pointer"},click:function(){App.windows.NewGame.selectArmy(0)
}}),$.chess.layer({left:110,top:145,width:94,height:52,html:'<div class="chess-army"><div class="army1"/></div>',css:{cursor:"pointer"},click:function(){App.windows.NewGame.selectArmy(1)}}),$.chess.layer({left:212,top:145,width:94,height:52,html:'<div class="chess-army"><div class="army2"/></div>',css:{cursor:"pointer"},click:function(){App.windows.NewGame.selectArmy(2)}}),$.chess.layer({left:8,top:208,width:94,height:52,html:'<div class="chess-army"><div class="army3"/></div>',css:{cursor:"pointer"},click:function(){App.windows.NewGame.selectArmy(3)
}}),$.chess.layer({left:110,top:208,width:94,height:52,html:'<div class="chess-army"><div class="army4"/></div>',css:{cursor:"pointer"},click:function(){App.windows.NewGame.selectArmy(4)}}),$.chess.layer({left:212,top:208,width:94,height:52,html:'<div class="chess-army"><div class="army5"/></div>',css:{cursor:"pointer"},click:function(){App.windows.NewGame.selectArmy(5)}}),$.chess.button({right:8,top:273,width:88,caption:"Start game",click:function(){App.windows.NewGame.hide();
$.chess.hideOverlay();var K,J={opponent:K=App.windows.NewGame.data("user"),color:["black","white"][$get("newgame.white").getValue()*1],army:App.windows.NewGame.selectedArmy,duration:$get("newgame.duration").getSelectedItem()*60};var I;App.request({page:"comm.php",repeat:3,data:{cmd:(I=App.windows.NewGame.data("quick_play")||K.bot)?"quick_game_invite":"game_invite",game_init_with:J.opponent.id,game_init_color:J.color,game_init_figures:J.army,game_time:J.duration,quick_play:I},success:function(L){if(L.status=="OK"){Game.newGame($.copy(J,{wait_item:WaitList.addItem('<a href="javascript:User.viewProfile('+J.opponent.id+'")>'+J.opponent.name.split(/\s/)[0]+"</a>"+LANG.WAITING_TO_ACCEPT_INVITATION),owner:true,id:L.data.response,server:0}))
}else{alert(App.handleError(L.data))}}})}}),$.chess.button({right:107,top:273,width:65,caption:"Cancel",click:function(){App.windows.NewGame.hide();$.chess.hideOverlay()}})]})]}).hide();App.windows.NewGame.selectedArmy=0;App.windows.NewGame.selectArmy=function(I){App.windows.NewGame.selectedArmy=I;$get("newgame.armyname").setText(App.armyName[I]);return App.windows.NewGame.find(".chess-army.selected").removeClass("selected").end().find(".chess-army:eq("+I+")").addClass("selected").end()
};App.windows.OfflineMessage=$.chess.window({parent:"#ontop-container",width:334,height:210,left:318,top:100,caption:LANG.FRIEND_IS_OFFLINE,ontop:true,draggable:true,widgets:[$.chess.frame({left:0,top:0,width:310,height:158,widgets:[F=$.chess.layer({left:4,top:6,width:30,height:24}),E=$.chess.label({left:43,top:6,width:254,height:60,color:"#fff",lineHeight:"16px",fontSize:"13px",text:LANG.OFFLINE_TEXT.replace("%friend%",'<span class="name"/>').replace("%him/her%",'<span class="to">him</span>').replace("%he/she%",'<span class="g">he</span>')}),$.chess.label({left:6,top:62,fontSize:"12px",text:LANG.OFFLINE_MESSAGE}),C=$.chess.editbox({left:6,top:79,width:235,height:23,maxlength:480,color:"#fff",fontSize:"12px",keypress:function(I){if(I.which==13){D.click()
}}}),D=$.chess.button({left:245,top:79,width:52,height:23,caption:LANG.OFFLINE_BTN_SEND,click:function(){var I=C.getText();C.setText(LANG.OFFLINE_MESSAGE_SENT).disable().removeClass("chess-editbox-hover").find("input").css("font-style","italic");$.chess.activate({});D.disable();User.sendOfflineMessage(App.windows.OfflineMessage.data("user_id"),I)}}),$.chess.button({right:5,bottom:5,width:54,height:23,caption:LANG.OFFLINE_BTN_CLOSE,click:function(){App.windows.OfflineMessage.hide();
$.chess.hideOverlay()}}),$.chess.button({right:67,bottom:5,height:23,caption:LANG.OFFLINE_BTN_VIRE_PROFILE,click:function(){User.viewProfile(App.windows.OfflineMessage.data("user_id"))}})]})]}).hide()}},updateStatus:function(B,A){Footbar.updateFriendStatus(B,A);$get("friendlist.tab").find(".chess-tab-online").html(LANG.ONLINE+" <span>("+B+")</span>").end().find(".chess-tab-offline").html(LANG.OFFLINE+" <span>("+A+")</span>")
}};Global.Friends={friends:{},online:0,offline:0,get:function(C,A){if(("id_"+C) in this.friends){return this.friends["id_"+C]}if(Global.BotList){for(var B=0;B<BotList.length;B++){if(BotList[B].id==C){return BotList[B]}}}return{id:A?C:0,name:A||"Somebody",short_name:A||"Somebody",online:!!A}},add:function(C){if(C==undefined){Footbar.updateFriendStatus(this.online+(Global.BotList&&BotList.length),this.offline);
return}var B=C,A=this;if(B.constructor!=Array){B=[C]}$.each(B,function(){var D=A.friends["id_"+this.id]=$.copy(this,{short_name:this.name.split(/\s/)[0],listIndex:-1});if(!("ranking" in D)){D.ranking=D.rank*1||1200}if(!D.image||!D.image.length){D.image=App.defaults.thumb_url}if(!D.avatar||!D.avatar.length){D.avatar=D.image}else{D.image=D.avatar}if(!D.image.match(/-thumb\.png$/i)){D.image=D.avatar=D.image.substr(0,D.avatar.length-4)+"-thumb.png"
}D.online=parseInt(D.online);D.gender=parseInt(D.gender);if(D.online){A.online++}else{A.offline++}});this.repopulate();FriendList.updateStatus(this.online+(Global.BotList&&BotList.length),this.offline)},repopulate:function(){var B=[],A=[];$.each(this.friends,function(C){if(!C.length){return true}if(this.online){Friends.friends[C].listIndex=B.length;B.push(this)}else{Friends.friends[C].listIndex=A.length;
A.push(this)}});FriendList.online.clear().addItems(B);FriendList.offline.clear().addItems(A);if(Global.BotList){FriendList.online.addItems(BotList)}},remove:function(D){var B,A="id_"+D;if(B=this.friends[A]){var C=B.online?LANG.ONLINE:LANG.OFFLINE;delete this.friends[A];this.repopulate()}},came_online:function(E,D){var B="id_"+E,C;if(B in this.friends){if(this.friends[B].online){return}this.offline--;
this.online++;(C=this.friends[B]).online=true;var A;if((A=Chatbar.chatbox.find('.chess-conversation[instanceid="'+E+'!conv"]')).length){A[0]._ui.came_online(C.short_name)}if(!D){this.repopulate();FriendList.updateStatus(this.online+(Global.BotList&&BotList.length),this.offline)}}},went_offline:function(F,D,E){var B="id_"+F,C;if(B in this.friends){if(!this.friends[B].online){return}this.offline++;this.online--;
(C=this.friends[B]).online=false;var A;if(!D&&(A=Chatbar.chatbox.find('.chess-conversation[instanceid="'+F+'!conv"]')).length){A[0]._ui.went_offline(C.short_name)}if(!E){this.repopulate();FriendList.updateStatus(this.online+(Global.BotList&&BotList.length),this.offline)}}},update_status:function(A){$.each(this.friends,function(B){if($.inArray(this.id,A)>=0){Friends.came_online(this.id,true)}else{Friends.went_offline(this.id,false,true)
}});this.repopulate();FriendList.updateStatus(this.online+(Global.BotList&&BotList.length),this.offline)}};Global.WaitList={items:0,lastid:0,textbox:{},create:function(){if(!("WaitList" in App.windows)){App.windows.WaitList=$.chess.window({small:true,parent:"#footer",right:250,top:-103,width:255,height:100,showCaption:false,widgets:[$.chess.label({left:2,top:0,text:LANG.WAITING_FOR,fontSize:"16px"}),WaitList.textbox=$.chess.textbox({name:"waitlist.textbox",left:0,top:18,width:231,height:62})]}).hide()
}},addItem:function(A){this.items++;var B="_w"+(this.lastid++);this.textbox.setText(this.textbox.getText()+'<p id="'+B+'" style="padding:0;margin:0">'+A+"</p>");Footbar.updateWaitingStatus();return B},removeItem:function(A){if(this.textbox.getText().match(new RegExp('<p id="'+A+'" style="[^"]+">',"i"))){this.items--;this.textbox.setText(this.textbox.getText().replace(new RegExp('<p id="'+A+'" style="[^"]+">.+?</p>',"i"),""));
Footbar.updateWaitingStatus()}}};Global.Chatbar={buttons:{},count:0,lastid:0,selected:null,chatbox:null,avatar:null,name:null,textbox:null,sending:null,container:null,holder:null,button_left:null,button_right:null,button_right2:null,create:function(){var A=$.chess.layer({name:"chatbar",parent:"#footer",left:270,top:7,width:$(window).width()-592,height:22,resize:function(B){Chatbar.container.setSize({width:B.width-70});
Chatbar.updateSlider()}}).show();this.container=$.chess.layer({name:"chatbar.container",parent:A,left:46,top:0,width:A.width()-70,height:22,css:{overflow:"hidden"}}).show();this.holder=$.chess.layer({name:"chatbar.holder",parent:this.container,left:0,top:0,width:0,height:22}).show();this.button_left=$.chess.button({name:"chatbar.slide_left",parent:A,left:0,top:0,width:19,height:22,caption:'<div class="arrow-l"><div/></div>',mousedown:function(){Chatbar.startScrolling("left")
},mouseup:function(){Chatbar.stopScrolling()}}).hide();this.button_right=$.chess.button({name:"chatbar.slide_right",parent:A,left:22,top:0,width:19,height:22,caption:'<div class="arrow-r"><div/></div>',mousedown:function(){Chatbar.startScrolling("right")},mouseup:function(){Chatbar.stopScrolling()}}).hide();this.button_right2=$.chess.button({name:"chatbar.slide_right2",parent:A,right:0,top:0,width:19,height:22,caption:'<div class="arrow-r"><div/></div>',mousedown:function(){Chatbar.startScrolling("right")
},mouseup:function(){Chatbar.stopScrolling()}}).hide();$(window).resize(function(){A.setSize({width:$(this).width()-592})});this.chatbox=App.windows.ChatBox=$.chess.window({small:true,parent:"#footer",left:0,top:-304,width:230,height:300,resizable:true,resizableOptions:{minHeight:250,minWidth:230,maxWidth:300},disableHandle:"w,s,nw,se,sw",showCaption:false,resize:function(B){Chatbar.name.setSize({width:B.client.width-55});
Chatbar.textbox.setSize({width:B.client.width+6});if(Chatbar.chatbox){$.each(Chatbar.chatbox.find(".chess-conversation"),function(){this._ui.setSize({width:B.client.width+6,height:B.client.height-80})})}},widgets:[this.avatar=$.chess.layer({left:-1,top:-1,width:30,height:24,css:{cursor:"pointer"},click:function(){User.viewProfile(Chatbar.chatbox.find(".chess-conversation:visible").data("userid")*1)
}}),this.name=$.chess.label({left:36,top:3,width:162,height:20,fontSize:"14px"}),$.chess.button({left:-3,top:28,width:80,height:19,fontSize:"11px",caption:LANG.SPECTATE,enabled:false,click:function(){}}),$.chess.button({left:82,top:28,width:100,height:19,fontSize:"11px",caption:LANG.WND_START_NEW_GAME_TITLE,click:function(){User.startGame(Chatbar.chatbox.find(".chess-conversation:visible").data("userid")*1)
}}),this.sending=$.chess.layer({right:1,top:30,width:16,height:16,html:'<img src="img/default/wait_small.gif" border="0" width="16" height="16" />'}).hide(),this.textbox=$.chess.editbox({left:-3,bottom:0,height:24,color:"#fff",fontSize:"12px",maxlength:480,resize:function(C){if(!Chatbar.textbox){return}var B=Chatbar.textbox.find(">input");B.width(B.width()-17)},keypress:function(F){if(F.which==13){var G=$.trim(Chatbar.textbox.getText());
Chatbar.textbox.setText("");if(G.length){var E=Chatbar.chatbox.find(".chess-conversation:visible"),D=E.data("chatid"),C=E.data("userid"),B=Friends.get(C).online;if(B&&(D==-1)){Chat.newSession(C,G,function(H){E.data("chatid",H)})}else{if(B){Chat.sendMessageToUser(C,G)}else{User.sendOfflineMessage(C,G);E[0]._ui.say(User.id,$.chess.timestamp(),G,C)}}}}}}),$.chess.button({right:1,top:1,width:16,height:16,caption:'<div class="xbutton"><div/></div>',click:function(){var B=Chatbar.chatbox.fadeOut(100).data("button_data");
Chat.closeSession(B.chat_id);Chatbar.removeButton(B.btn_index)}}),$.chess.button({right:19,top:1,width:16,height:16,caption:'<div class="minbutton"><div/></div>',click:function(){Chatbar.clickButton(Chatbar.chatbox.data("button_data").btn_index)}})]}).hide();this.sending.hide();this.chatbox.find(".chess-window-content").css("overflow","visible");this.textbox.find(">input").css("left",20).end().append($.chess.layer({left:4,top:5,width:17,height:13,html:$.chess.transPNG("img/default/chat.png",17,13)}).show())
},buttonExists:function(A,B){var C=false;$.each(Chatbar.buttons,function(D){if(this.data("btn_data").user_id==A){B=D;return !(C=true)}});return C},openChat:function(D,C,E){var F,H=false;if(this.buttonExists(D,F)){if(this.buttons[F]!=this.selected){this.clickButton(F)}else{Chatbar.textbox.find(">input").focus()}}else{C=C||-1;H=true;var B=Friends.get(D),A=D+"!conv";(E?function(){}:this.clickButton)(this.addButton(B.name,{chatid:C,user_id:D,typed:"",click:function(){Chatbar.avatar.jq().html($.chess.transPNG(B.avatar,30,24));
Chatbar.name.setText(B.name);Chatbar.chatbox.find(".chess-conversation").hide().end().find('[instanceid="'+A+'"]').fadeIn(1,function(){this._ui.update()})}}));var I=this.chatbox.getSize(),G;if(!(G=Chatbar.chatbox.find('[instanceid="'+A+'"]')).length){G=$.chess.conversation({name:A,parent:this.chatbox.find(".chess-window-content"),left:-3,top:52,width:I.width-18,height:I.height-106}).data("chatid",C).data("userid",D)
}else{if(H){G.data("chatid",-1)}}if(!E&&G.length){G.show()}}},addButton:function(A,C){var B="_"+(this.lastid++);this.buttons[B]=$.chess.button({parent:this.holder,left:this.count*147,top:0,width:140,height:22,caption:A,click:function(){Chatbar.clickButton(B)}}).data("btn_index",B).data("btn_data",C).show();this.count++;this.updateSlider();return B},clickButton:function(B){var C=Chatbar.buttons[B];if(C){if(Chatbar.selected){Chatbar.selected.find(".chess-button-content").css("color","#e7c200")
}var A=Chatbar.chatbox.find('[instanceid="'+C.data("btn_data").user_id+'!conv"]').data("chatid");if(Chatbar.selected==C){var E=Chatbar.chatbox.is(":visible");C.find(".chess-button-content").css("color",E?"#e7c200":"#fff");Chatbar.chatbox[E?"fadeOut":"fadeIn"](100);if(!E){Chatbar.textbox.find(">input").focus()}Chatbar.setSessionOpen(A,!E);return}C.find(".chess-button-content").css("color","#fff");Chatbar.ensureVisible(B);
Chatbar.updateChatboxPosition(parseInt(C.css("left")));Chatbar.chatbox.data("button_data",{btn_index:B,chat_id:A}).fadeIn(100);if(Chatbar.selected){var D=Chatbar.selected.data("btn_data");D.typed=Chatbar.textbox.getText();Chatbar.setSessionOpen(A);Chatbar.selected.data("btn_data",D)}Chatbar.selected=C;Chatbar.setSessionOpen(A);Chatbar.textbox.find(">input").val(C.data("btn_data").typed).focus();(C.data("btn_data").click||function(){})()
}},setSessionOpen:function(A,B){if(B==undefined){B=true}var C;if(C=Chat.sessions["id_"+A]){$.each(Chat.sessions,function(D){if(D.length){Chat.sessions[D].open=false}});C.open=B}},updateChatboxPosition:function(A,F){var G=A+parseInt(this.container.css("left"))+parseInt(this.holder.css("left"))+271,D=this.chatbox.width(),E=this.container.width(),C=false;if(G+D>271+E){F?C=true:G=316+E-D}else{if(G<324){F?C=true:G=324
}}if(C){var B=this.chatbox.data("button_index");if(this.buttons[B]){this.buttons[B].find(".chess-button-content").css("color","#e7c200")}this.chatbox.removeData("button_index").hide()}this.chatbox[C?"hide":"show"]().setPosition({left:G})},ensureVisible:function(C){var E;if(E=this.buttons[C]){var A=parseInt(E.css("left")),B=parseInt(this.holder.css("left")),D=this.container.width();if(A+B<0){this.holder.css("left",-A)
}else{if(A+B+140>D){this.holder.css("left",D-(A+140))}}}},removeButton:function(B){if(B in this.buttons){this.count--;this.updateSlider();var A=this.buttons[B].data("btn_data").user_id;$.chess.destroy(this.buttons[B]);var C=parseInt(this.buttons[B].css("left"));this.buttons[B].remove();$.each(this.buttons,function(){var D;if((D=parseInt(this.css("left")))>C){this.css("left",D-147)}});if(this.selected==this.buttons[B]){this.selected=null
}Chat.closeSession("id_"+Chatbar.chatbox.find('.chess-conversation[instanceid="'+A+'!conv"]').data("chatid"));delete this.buttons[B]}},scrollTimer:null,startScrolling:function(F){var B=10*(2*(F=="left")-1);var D=this.container.width()-this.holder.width(),A=0,E=this.container.width(),C=this.holder.width();this.scrollTimer=setInterval(function(){var G=parseInt(Chatbar.holder.css("left"))+B;if(G<D){G=D
}else{if(G>A){G=A}}Chatbar.holder.css("left",G);if(Chatbar.chatbox.is(":visible")){Chatbar.updateChatboxPosition(parseInt(Chatbar.buttons[Chatbar.chatbox.data("button_data").btn_index].css("left")),true)}Chatbar.updateBorders(G,C,E)},50)},stopScrolling:function(){clearInterval(this.scrollTimer)},updateBorders:function(A,B,C){if(A<-1){this.container.css("border-left","1px solid #645c5c")}else{this.container.css("border-left","1px solid transparent")
}B=B||this.holder.width();C=C||this.container.width();if(B-C+A>1){this.container.css("border-right","1px solid #645c5c")}else{this.container.css("border-right","1px solid transparent")}},updateSlider:function(){var B,D;this.holder.width(B=this.count*147-7);var C=B>(D=this.container.width())?"fadeIn":"fadeOut";this.button_left[C](200);this.button_right[C](200);this.button_right2[C](200);var A;if(C=="fadeOut"){A=this.holder.css("left",0)&&0
}else{A=parseInt(this.holder.css("left"))}this.updateBorders(A,B,D)}};Global.Footbar={loaded:false,create:function(){$("#footer").show();FriendList.create();WaitList.create();Game.create();Chatbar.create();Notifications.create();$.chess.button({parent:"#footer",name:"footbar.friends",caption:LANG.BTN_FRIENDS,left:25,top:8,height:23,click:function(){App.windows.FriendList[App.windows.FriendList.is(":visible")?"fadeOut":"fadeIn"](100)
}}).show();$.chess.label({parent:"#footer",name:"footbar.status",left:120,top:12,width:145,color:"#fff",fontSize:"11px"}).show();$.chess.button({parent:"#footer",name:"footbar.notifications",caption:LANG.BTN_NOTIFICATIONS,right:25,top:8,height:23,click:function(){var A=App.windows.NotifyBox.is(":visible");App.windows.NotifyBox[A?"fadeOut":"fadeIn"](100);if(A){Notifications.list.markAllRead();Footbar.updateUnreadedNoties(Notifications.unreaded=0)
}}}).show();$.chess.label({parent:"#footer",name:"footbar.unreaded",right:120,top:12,width:165,align:"right",color:"#fff",fontSize:"11px"}).show();$.chess.layer({parent:"#footer",name:"footbar.waiting",right:260,top:6,width:50,height:24,css:{"text-align":"right",cursor:"pointer","line-height":"24px"},html:'<img width="24" height="24" src="img/default/waiting.gif" style="vertical-align:center;float:right;margin-left:2px" /><span style="color:#bab7b7;font-size:12px;display:block;float:right;width:20px"></span>',click:function(){App.windows.WaitList[App.windows.WaitList.is(":visible")?"fadeOut":"fadeIn"](100)
}}).hide();this.loaded=true},updateFriendStatus:function(B,A){if(!this.loaded){return}if(B+A==0){$get("footbar.status").setText(LANG.NO_FRIENDS_YET);$get("footbar.friends").disable()}else{$get("footbar.status").setText(LANG.FRIENDS_ONLINE.replace("%online%",'<span style="color:#f9d300;font-weight:bold">'+B+"</span>").replace("%total%","<strong>"+(B<<0+A<<0)+"</strong>"));$get("footbar.friends").enable()
}},updateUnreadedNoties:function(A){if(!this.loaded){return}if(A==0){$get("footbar.unreaded").setText("")}else{$get("footbar.unreaded").setText(A==1?LANG.UNREADED_ITEM:LANG.UNREADED_ITEMS.replace("%items%",'<span style="color:#f9d300;font-weight:bold">'+A+"</span>"))}},updateWaitingStatus:function(){if(!this.loaded){return}if($.browser.msie||WaitList.items==0){$get("footbar.waiting").hide();if(App.windows.WaitList.is(":visible")){App.windows.WaitList.fadeOut(100)
}}else{$get("footbar.waiting").find(">span").text(WaitList.items).end().show()}}};Global.Game={waiting:{length:0},running:{length:0,add:function(B,A){Game.running[B]=A;Game.running.length++;return Game.running[B]},remove:function(A){delete Game.running[A];Game.running.length--}},finished:{},getGameList:function(){var E={},D=0,B=$.chess.timestamp(),A=[];for(var C in this.waiting){if(C.substr&&(C.substr(0,3)=="id_")){D++;
if((B-this.waiting[C].created)>=600){E[C]=-1;A.push(C)}else{E[C]=0}}}if(A.length){$.each(A,function(){var H=Game.waiting[this];Notifications.list[0]._ui.add(LANG.GAME_REQUEST,'<a href="javascript:User.viewProfile('+H.opponent.id+')">'+H.opponent.short_name+"</a>"+LANG.INVITATION_IGNORED,$.chess.timestamp());WaitList.removeItem(H.wait_item);delete Game.waiting[this];Game.waiting.length--})}for(var G in this.running){var F=this.running[G];
if(G.length&&(G.substr(0,3)=="id_")&&(F.my_move===-1||F.my_move===false)){D++;E[G]=F.my_move==-1?0:F.last_move*1+1}}return D?E:undefined},getGamePingList:function(){var A=[];$.each(this.running,function(B){if(B.length&&(B.substr(0,3)=="id_")&&this.my_move===true){A.push(this.id)}});return A.length?A:undefined},newGame:function(A){if($("#board").length==0){App.redirect("/dashboard.php?act="+App.broadcast_action("wait_for_game",A))
}else{this.waiting["id_"+A.id]=$.copy(A,{last_move:0,my_move:-1,created:$.chess.timestamp()});Game.waiting.length++}},joinGame:function(B,D){var A=B;var C={cmd:"game_join",game_id:A.id,game_join_figures:A.army};if(!C.game_id||typeof C.game_join_figures=="undefined"){return}App.request({page:"comm.php",server:A.server,repeat:3,data:C,success:function(E){if(E.status=="OK"){var H="id_"+A.id,G=Game.running.add(H,$.copy(A,{my_move:A.color=="white"}));
var F=("id_"+G.opponent.id) in Friends.friends?0:G.opponent.id;Game.running[H].loaded=false;Board.start(H,G.duration,User.name,G.opponent.name,G.color,User.classic_pieces,G.army,G.opponent_army,G.owner,(("id_"+F) in (Global.Bots||{}))?0:F*1)}else{alert(App.handleError(E.data))}}})},rejectGame:function(A){App.request({page:"comm.php",server:A.server,repeat:3,data:{cmd:"game_reject",game_id:A.game_id},success:function(B){if(B.status=="ERR"){}}})
},ready:function(C,D){if(C in this.waiting){WaitList.removeItem(this.waiting[C].wait_item);var B=this.running.add(C,$.copy(this.waiting[C],{opponent_army:D.game_join_figures,last_move:0,my_move:this.waiting[C].color=="white",opponent_offered_draw:false}));delete this.waiting[C];Game.waiting.length--;var A=("id_"+B.opponent.id) in Friends.friends?0:B.opponent.id;Game.running[C].loaded=false;Board.start(C,B.duration,User.name,B.opponent.name,B.color,User.classic_pieces,B.army,B.opponent_army,B.owner,(("id_"+A) in (Global.Bots||{}))?0:A*1)
}},rejected:function(B){if(B in this.waiting){var A=this.waiting[B];App.request({page:"comm.php",server:A.server,data:{skipUpdate:true,cmd:"game_over",game_id:A.id,game_status:"OK"}});Notifications.list[0]._ui.add(LANG.GAME_REQUEST,'<a href="javascript:User.viewProfile('+A.opponent.id+')">'+A.opponent.short_name+"</a>"+LANG.INVITATION_REJECTED,$.chess.timestamp());WaitList.removeItem(this.waiting[B].wait_item);
delete this.waiting[B];Game.waiting.length--}},started:function(A){if(A in this.running){this.running[A].started=true;Board.start_clock(A)}},playing:function(A,B){if((A in this.waiting)&&(this.waiting[A].last_move==0)&&(this.waiting[A].color=="black")){Game.joinGame(A,B)}if(A in this.running&&(this.running[A].last_move==B.move_num-1)){if(!this.running[A].loaded){this.running[A].playing_data=B}else{Board.move(A,B.move_num,B.move,B.game_time/1000,false,false);
this.running[A].last_move=B.move_num;this.running[A].my_move=true}}},draw_offered:function(A,B){if(A in this.running){this.running[A].opponent_offered_draw=true;Board.move(A,B.move_num,B.move,B.game_time/1000,true,false)}},end_game:function(A,B){if(B.status.substr(1)=="resign"){Board.resign(A)}else{if(B.status=="draw_accepted"){Board.draw_accepted(A)}else{Board.move(A,B.move_num,B.move,B.game_time/1000,false,true)
}}this.running.remove(A)},timeout:function(A){Board.timeout(A)},user_off:function(A){Board.user_off(A)},game_move:function(C,E,B,D,F,A){this.running[C].moveinfo={draw_rejected:this.running[C].opponent_offered_draw,offer_draw:!this.running[C].opponent_offered_draw&&A,data:{move_num:E,move:B,movePGN:D,time:F*1000}};this.running[C].opponent_offered_draw=false;this.running[C].last_move=E},game_state:function(B,D){var A=this.running[B],C={cmd:"game_move",game_id:B.substr(3)};
if((D!="timeout")&&(typeof A.moveinfo!="object")){return}if(D=="timeout"){C.cmd="game_end";C.type="timeout";C.move_num=(A.last_move*1+1)||1;this.running.remove(B)}else{if(D=="checkmate"||D=="draw"||D=="stalemate"){C.cmd="game_end";C.type=D=="stalemate"?"draw":D;C=$.extend(C,A.moveinfo.data);this.running.remove(B)}else{if(A.moveinfo.draw_rejected){C.cmd="game_draw_reject"}else{if(A.moveinfo.offer_draw){C.cmd="game_draw_offer"
}}C=$.extend(C,A.moveinfo.data);this.running[B].my_move=false}}console.log(C);App.request({page:"comm.php",data:C,success:function(E){if(E.status=="ERR"){}}});this.running[B].moveinfo=false},game_end:function(A){App.request({page:"comm.php",data:{cmd:"game_over",game_id:A.substr(3),game_status:"OK"},success:function(B){if(B.status=="ERR"){}}});this.running.remove(A)},game_invalid_move:function(A){App.request({page:"comm.php",data:{cmd:"game_over",game_id:A.substr(3),game_status:"INVALID"},success:function(B){if(B.status=="ERR"){}}});
this.running.remove(A)},game_accept_draw:function(A){App.request({page:"comm.php",data:{cmd:"game_draw_accept",game_id:this.running[A].id},success:function(B){if(B.status=="ERR"){}}});this.running.remove(A)},game_resign:function(A){App.request({page:"comm.php",data:{cmd:"game_resign",game_id:this.running[A].id},success:function(B){if(B.status=="ERR"){}}});this.running.remove(A)},game_all_closed:function(){$("#board").hide();
$("#dashboard-content").show();Board.instance=null;Board.processed_queue=false;Board.ready=false},game_add_friend:function(A){Global.User.sendFriendRequest(A,function(){alert(LANG.FRIEND_REQUEST_SENT)},function(B){if(B=="ALREADY_PENDING"){alert(LANG.FRIEND_REQUEST_PENDING)}else{if(B=="ALREADY_IGNORED"){alert(LANG.FRIEND_REQUEST_IGNORED)}else{if(B=="ALREADY_BLOCKED"){alert(LANG.FRIEND_REQUEST_BLOCKED)
}else{if(B=="ALREADY_CONFIRMED"){alert(LANG.FRIEND_REQUEST_CONFIRMED)}}}}})},create:function(){if(!("StartGame" in App.windows)){var D,B=-1,A=function(F){var E=B;B=F;if(E>-1){App.windows.StartGame.find(".chess-army:eq("+E+")").css("opacity",1).siblings(".opponent-army").remove()}App.windows.StartGame.find(".chess-army:eq("+F+")").css({opacity:0.5,cursor:"default"}).parent().append($('<div class="opponent-army" />').css({position:"absolute",left:"11px",top:"19px",width:"77px",height:"22px"}).append($.chess.transPNG("img/default/opponent.png",77,22)))
},C=function(F,E){if(E&&F==B){F=F==App.armyName.length-1?0:F+1}D=F;$get("startgame.armyname").setText(App.armyName[F]);App.windows.StartGame.find(".chess-army.selected").removeClass("selected").end().find(".chess-army:eq("+F+")").addClass("selected")};App.windows.StartGame=$.chess.window({parent:"#ontop-container",width:344,height:363,left:324,top:95,caption:LANG.WND_START_GAME_TITLE,ontop:true,draggable:true,widgets:[$.chess.frame({left:0,top:0,width:320,height:311,widgets:[$.chess.label({left:8,top:7,width:78,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_GAME_OPPONENT}),$.chess.label({name:"startgame.opponent",left:110,top:7,width:216,height:25,lineHeight:"22px",fontSize:"14px",color:"#fff"}),$.chess.label({left:8,top:42,width:78,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_GAME_PLAY_AS}),$.chess.label({name:"startgame.color",left:110,top:42,width:78,height:25,lineHeight:"22px",fontSize:"14px",color:"#fff"}),$.chess.label({left:8,top:77,width:78,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_GAME_DURATION}),$.chess.label({name:"startgame.duration",left:110,top:77,width:78,height:25,lineHeight:"22px",fontSize:"14px",color:"#fff"}),$.chess.label({left:8,top:112,width:120,height:25,lineHeight:"22px",fontSize:"14px",text:LANG.WND_START_GAME_SELECT_ARMY}),$.chess.label({name:"startgame.armyname",left:110,top:112,width:216,height:25,lineHeight:"22px",fontSize:"14px",color:"#fff"}),$.chess.layer({left:8,top:145,width:94,height:52,html:'<div class="chess-army"><div class="army0"/></div>',css:{cursor:"pointer"},click:function(){if(B!=0){C(0)
}}}),$.chess.layer({left:110,top:145,width:94,height:52,html:'<div class="chess-army"><div class="army1"/></div>',css:{cursor:"pointer"},click:function(){if(B!=1){C(1)}}}),$.chess.layer({left:212,top:145,width:94,height:52,html:'<div class="chess-army"><div class="army2"/></div>',css:{cursor:"pointer"},click:function(){if(B!=2){C(2)}}}),$.chess.layer({left:8,top:208,width:94,height:52,html:'<div class="chess-army"><div class="army3"/></div>',css:{cursor:"pointer"},click:function(){if(B!=3){C(3)
}}}),$.chess.layer({left:110,top:208,width:94,height:52,html:'<div class="chess-army"><div class="army4"/></div>',css:{cursor:"pointer"},click:function(){if(B!=4){C(4)}}}),$.chess.layer({left:212,top:208,width:94,height:52,html:'<div class="chess-army"><div class="army5"/></div>',css:{cursor:"pointer"},click:function(){if(B!=5){C(5)}}}),$.chess.button({right:8,top:273,width:88,caption:LANG.WND_START_GAME_BTN_START,click:function(){App.windows.StartGame.hide().data("callback").accept($.extend(App.windows.StartGame.data("gameData"),{army:D}));
$.chess.hideOverlay()}}),$.chess.button({right:107,top:273,width:65,caption:LANG.WND_START_GAME_BTN_REJECT,click:function(){App.windows.StartGame.hide().data("callback").deny();$.chess.hideOverlay()}})]})]}).hide();App.windows.StartGame.selectArmy=function(F,E){C(F,E);return App.windows.StartGame};App.windows.StartGame.opponentArmy=function(E){A(E);return App.windows.StartGame}}},move_history:function(C,A,B){}};
$.each(["move","state","end","invalid_move","accept_draw","resign","all_closed","add_friend"],function(){var A="game_"+this;Global[A]=function(){console.log(A+" called:",arguments);Game[A].apply(Game,arguments)}});Global.board_loaded=function(A){var B;console.log("board_loaded called:",arguments);if((A in Game.running)&&(!Game.running[A].loaded)){Game.running[A].loaded=true;if(B=Game.running[A].playing_data){Game.playing(A,B)
}}};