/*! 2018-07-13 */
function changeLuck(a){-1!=a&&getReady()}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(),getReady(),$(".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})},getReady=function(){var a=$("#tagid").val();if(-1==a)return!1;$(".lottery-right .result-line").remove(),$.getJSON(PATH_ACTIVITY+Path_url("ajax_act_lottory.php?action=ready"),{from:"cjx",awardid:a},function(a){if(console.log(a),0==a.ret&&a.data.length>0){Players=a.data;Players.length;$(".usercount-label").html(a.count+"人"),$("#leftperson").val(a.count),$(".control.button-run").fadeIn(),null!=a.luckuser&&$.each(a.luckuser,function(a,b){var c=a+1,d='<div class="result-line had_luck_user" style="display: block;">';d+='<div class="result-num">'+c+"</div>",d+='<div class="user" style="background-image: url('+b.avatar+');">',d+='<span class="nick-name">'+b.nick_name+"</span></div></div>",$(".lottery-right").prepend(d)})}else alert("检测抽奖池没有用户或是用户被其他抽奖功能全部抽完了")}).fail(function(){alert("您断网了，请检查网络连接是否正常")})},getUser=function(a){audio_GetOne&&audio_GetOne.play(),$(".lottery-right").scrollTop(0);var b=$(".lottery-right").scroll(0).children(".result-line").length,c=$ResultSeed.clone();c.find(".result-num").html(b+1),c.prependTo(".lottery-right").slideDown();var d=c.offset();$(".lottery-run").addClass("moving"),$(".lottery-run").removeClass("box-moving"),window.setTimeout(function(){window.setTimeout(function(){$(".lottery-run").removeClass("moving")},1e3);var b=$(".lottery-run .user"),e=b.clone().appendTo("body").css({position:"absolute",top:b.offset().top,left:b.offset().left,width:b.width(),height:b.height()}).addClass("").animate({width:60,height:60,top:d.top+5,left:d.left+50},500,function(){var b=e.css("background-image");e.appendTo(c).removeAttr("style").css({"background-image":b}),$.isFunction(a)&&a.call(this)})},3e3)},start_game=function(){if(parseInt($(".usercount-label").text())<=0)return alert("所有的人都已经抽完了"),!1;winer_count=1*$("#num").val(),winer_count<=Players.length?($(".lottery-run").removeClass("moving"),$(".lottery-run").addClass("box-moving"),$(".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(),audio_Running&&audio_Running.pause(),$.isArray(Players)?(winer_count=1*$("#num").val(),winer_count<=Players.length?getWiner():alert("计划选"+winer_count+"人，但是只剩"+Players.length+"人可选，请减少选取数！")):alert("无法获得游戏数据，与游戏服务器断开，请刷新重试！")},winer_count=0,getwinner_status=!1,getWiner=function(){if(0==getwinner_status){getwinner_status=!0,flgPlaying=!1,window.clearTimeout(tmr_playanimate);for(var a,b=!1,c=Players.length,d=0;d<c;d++)if(2==Players[d].designated){b=d,a=Players.splice(b,1)[0];break}for(;!1===b;)b=Math.floor(Math.random()*Players.length),3!=Players[b].designated?a=Players.splice(b,1)[0]:b=!1;$.ajax({url:"ajax_act_lottory.php?action=ok",data:{openid:a.openid,awardid:$("select[name=luckTag]").val(),from:"cjx"},type:"post",dataType:"json",async:!0,success:function(a){if(a.ret>0){var b=$("#leftperson").val();b-=1,$("#leftperson").val(b),$(".usercount-label").html(b+"人"),$(".lottery-run .user").css({"background-image":"url("+a.data.avatar+")"}),$(".lottery-run .user .nick-name").html(a.data.nick_name),$(".lottery-run .user .mobile").html(a.data.mobile)}getwinner_status=!1},error:function(){alert("您断网了，请检查网络连接是否正常"),getwinner_status=!1}}),window.setTimeout(function(){getUser(function(){winer_count--,winer_count>0?(flgPlaying=!0,window.setTimeout(function(){playanimate(),getWiner()},1e3)):$(".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),curr_index++,curr_index>=Players.length&&(curr_index=0),flgPlaying&&(tmr_playanimate=window.setTimeout(playanimate,100))}};