/*! 2018-07-13 */
var $ResultSeed,Players,Winers,audio_Running,audio_GetOne,resizePart=window.WBActivity.resize=function(){},start=window.WBActivity.start=function(){window.WBActivity.hideLoading();var a=document.getElementById("Audio_Running");a.play&&(audio_Running=a);var b=document.getElementById("Audio_Result");b.play&&(audio_GetOne=b),$(".usercount-label").html("加载数据中..."),$(".control").hide(),$(".Panel.Top").css({top:0}),$(".Panel.Bottom").css({bottom:0}),$(".Panel.Lottery").css({display:"block",opacity:1}),$ResultSeed=$(".lottery-right .result-line"),$(".control.button-run").on("click",function(){start_game()}),$(".control.button-stop").on("click",function(){stop_game()}),$(".control.button-nextround").on("click",function(){window.location.reload()}),$(".button-reload").on("click",function(){window.location.reload()}),$(".select-button").on("click",function(a){var b=$(this),c=$(".select-value"),d=c.text();return b.hasClass("minus")?d>1&&(d--,c.text(d)):b.hasClass("plus")&&(d<Players.length?d++:c=Players.length,c.text(d)),a.preventDefault(),!1})},getUser=function(a){audio_GetOne&&audio_GetOne.play(),$(".lottery-right").scrollTop(0);var b=$(".lottery-right").scroll(0).children(".result-line").length-1,c=$ResultSeed.clone();c.find(".result-num").html(b+1),c.prependTo(".lottery-right").slideDown();var d=c.offset(),e=$(".lottery-run .user"),f=e.clone().appendTo("body").css({position:"absolute",top:e.offset().top,left:e.offset().left,width:e.width(),height:e.height()}).animate({width:60,height:60,top:d.top+5,left:d.left+50},500,function(){var b=f.css("background-image");f.appendTo(c).removeAttr("style").css({"background-image":b}),$.isFunction(a)&&a.call(this)})},start_game=function(){console.log(Players),winer_count=1*$(".select-value").text(),winer_count<=Players.length?($(".control.button-run").hide(),flgPlaying=!0,playanimate(),audio_Running&&audio_Running.play(),window.setTimeout(function(){$(".control.button-stop").fadeIn()},500)):alert("计划选"+winer_count+"人，但是只剩"+Players.length+"人可选，请减少选取数！")},stop_game=function(){$(".control.button-stop").hide(),$.isArray(Players)?(winer_count=1*$(".select-value").text(),winer_count<=Players.length?getWiner():alert("计划选"+winer_count+"人，但是只剩"+Players.length+"人可选，请减少选取数！")):alert("无法获得游戏数据，与游戏服务器断开，请刷新重试！")},winer_count=0,getWiner=function(){flgPlaying=!1,window.clearTimeout(tmr_playanimate);var a=Math.floor(Math.random()*Players.length),b=Players.splice(a,1)[0];$(".lottery-run2 .toux1").css({"background-image":"url("+b.avatar+")"});var c=Math.floor(Math.random()*Players.length),d=Players.splice(c,1)[0];$(".lottery-run2 .toux2").css({"background-image":"url("+d.avatar+")"});var e=Math.floor(Math.random()*Players.length),f=Players.splice(e,1)[0];$(".usercount-label").html(Players.length+"人"),$(".lottery-run .toux3").css({"background-image":"url("+f.avatar+")"}),$(".lottery-run .user .nick-name").html(f.nick_name);var g=Math.floor(Math.random()*Players.length),h=Players.splice(g,1)[0];$(".lottery-run2 .toux4").css({"background-image":"url("+h.avatar+")"});var i=Math.floor(Math.random()*Players.length),j=Players.splice(i,1)[0];$(".lottery-run2 .toux5").css({"background-image":"url("+j.avatar+")"}),window.setTimeout(function(){getUser(function(){winer_count--,winer_count>0?(flgPlaying=!0,playanimate(),window.setTimeout(function(){getWiner()},1500)):(audio_Running&&audio_Running.pause(),$(".control.button-run").fadeIn())})},500)},curr_index=0,flgPlaying=!1,tmr_playanimate,playanimate=function(){if(Players[curr_index]){var a=Players[curr_index];$(".lottery-run .user").css({"background-image":"url("+a.avatar+")"}),$(".lottery-run .user .nick-name").html(a.nick_name);var b=Math.floor(Math.random()*Players.length),c=Players.splice(b,1)[0];$(".lottery-run2 .toux1").css({"background-image":"url("+c.avatar+")"});var d=Math.floor(Math.random()*Players.length),e=Players.splice(d,1)[0];$(".lottery-run2 .toux2").css({"background-image":"url("+e.avatar+")"});var f=Math.floor(Math.random()*Players.length),g=Players.splice(f,1)[0];$(".lottery-run2 .toux4").css({"background-image":"url("+g.avatar+")"});var h=Math.floor(Math.random()*Players.length),i=Players.splice(h,1)[0];$(".lottery-run2 .toux5").css({"background-image":"url("+i.avatar+")"}),curr_index++,curr_index>=Players.length&&(curr_index=0),flgPlaying&&(tmr_playanimate=window.setTimeout(playanimate,100))}};