/*! 2018-07-13 */
function changeLuck(a){-1!=a&&getReady()}var $ResultSeed,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()})},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:"zjd",awardid:a},function(a){0==a.ret&&null==a.data?($(".usercount-label").html("0"),alert("所有人都已经中奖了")):0==a.ret&&a.data.length>0?($(".usercount-label").html(a.count),$(".control.button-stop").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)})):alert("数据异常，无法进行抽奖，请刷新！")}).fail(function(){alert("无法连接服务器，请重试")})},getUser=function(a){window.setTimeout(function(){audio_GetOne&&audio_GetOne.play()},400),$(".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)})},1500)},stop_game=function(){$(".control.button-stop").hide();var a=$(".usercount-label").text(),b=parseInt(a);if((b=isNaN(b)?0:b)<=0)return alert("已经没有人可以参与抽奖了"),$(".control.button-stop").fadeIn(),!1;winer_count=1*$("#num").val(),winer_count<=b?getWiner():(alert("计划选"+winer_count+"人，但是只剩"+b+"人可选，请减少选取数！"),$(".control.button-stop").fadeIn())},winer_count=0,getWiner=function(){$.ajax({url:"ajax_act_lottory.php?action=ok",data:{awardid:$("select[name=luckTag]").val(),from:"zjd"},type:"post",dataType:"json",async:!0,success:function(a){if(a.ret>0){var b=parseInt($(".usercount-label").html());b=b-1>0?b-1:0,$(".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)}},error:function(){alert("您断网了，请检查网络连接是否正常")}}),window.setTimeout(function(){getUser(function(){winer_count--,winer_count>0?window.setTimeout(function(){getWiner()},600):(audio_Running&&audio_Running.pause(),$(".control.button-stop").fadeIn())})},1e3)};