<?php /* Smarty version 2.6.17, created on 2018-05-28 14:57:36
         compiled from events_vote.html */ ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "header.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

<!--公用标题居中显示-->
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "common_header.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "events_top.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "events_infos.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

<!--公用提示背景遮罩层-->
<div class="a_cover"></div>

<!--vote_tips begin-->
<div class="v_tips_box" id="vote_tips_box">
    <div class="v_close_btn" id="tips_close_btn"></div>
    <p class="vote_result">投票成功</p>
</div>
<!--vote_tips end-->

<script>
var seconds = 1000;
var goUrl = '';
var config_total_vote_num = '<?php echo $this->_tpl_vars['voteInfo']['total_vote_num']; ?>
';
function go_page(){
	location.href = goUrl;
}
function authorizeRun(data_msg_url){
	$(".vote_result").html('本活动需登录后才可以参与');
	$('.tips_close_btn').show();
	$('.v_tips_box, .a_cover').fadeIn();
	goUrl= '<?php echo $this->_tpl_vars['loginUrl']; ?>
';
	setInterval("go_page();",seconds+100);
}

function Percentage(num, total) { 
    return Math.round(num / total * 100);// 小数点后两位百分比
}

$("#tips_close_btn").on('click', function(){
	$(".v_tips_box,.a_cover").hide();
	if(goUrl){
		go_page();
	}
});

KISSY.use('node, io, json', function (S, Node, IO, JSON) {
	var cell_colors = JSON.parse('<?php echo $this->_tpl_vars['cell_colors']; ?>
');
	
	//视频自适应
	var screenWidth = $(window).width();
	var baseWidth = 510;
	var video_scale = screenWidth / baseWidth;
	$(".video_iframe").each(function () {
		var new_width = $(this).width() * video_scale;
		$(this).width(new_width - 20);
		var new_height = $(this).height() * video_scale;
		$(this).height(new_height - 20);
	});
	
<?php if ($this->_tpl_vars['voteInfo']['vote_type'] == 1): ?>
	<?php if ($this->_tpl_vars['eventsStatus']): ?> 	refreshVoteBox(false);
	
	<?php else: ?>
	
	
	
	
	$(".lable_div").on('click', function () {
		
		var _self = $(this);
		var voteid = $(this).data('voteid');
		var total_vote_num = config_total_vote_num;
		if (!voteid) {
			return false
		}
		
		IO.on("send",function(){
			showLoading();
		});
		
		IO.get('<?php echo $this->_tpl_vars['web_cfg']['domain']; ?>
/?c=eventsVote&a=vote'
			, {
				events_id: '<?php echo $this->_tpl_vars['voteInfo']['id']; ?>
',
				voteid: voteid
			}
			, function (data) {
				goUrl = '';
				if (data.ok) {
					showMsg('投票成功', function () {
						var addNum = _self.find('em').data('num') + 1;
						_self.find('em').data('num', addNum);
						total_vote_num = Number(total_vote_num) + 1;
						config_total_vote_num = total_vote_num;
						refreshVoteBox(true);
					});
				} else {
					if(data.msg.url){
						authorizeRun(data.msg.url);
						return false;
					}
					showMsg(data.msg, null, function () {
						refreshVoteBox(false);
					});
				}
			}
			, 'json'
		);
	});
	
	$(".vote_btn").click(function(){
		$(this).find("span").addClass("h_selected");
		$(".vote_btn p").each(function(){
			$(this).show(600);//右侧推出显示投票数,速度可控制
		});
	});
	<?php endif; ?>
<?php else: ?>
	<?php if ($this->_tpl_vars['eventsStatus']): ?> 	$(".vote_btn p").each(function(){
		$(this).show(600);//右侧推出显示投票数,速度可控制
	});
	<?php else: ?>
	$(".vote_btn").click(function () {
		
		var _self = $(this);
		var voteid = $(this).data('voteid');
		S.log(voteid);
		if (voteid == '') {
			return false
		}
		
		IO.on("send",function(){
			showLoading();
		});
		
		IO.get('<?php echo $this->_tpl_vars['web_cfg']['domain']; ?>
/?c=eventsVote&a=vote'
			, {
				events_id: '<?php echo $this->_tpl_vars['voteInfo']['id']; ?>
',
				voteid: voteid
			}
			, function (data) {
				goUrl = '';
				if (data.ok) {
					showMsg('投票成功', function () {
						_self.find("span").addClass("h_selected");
						var addNum = _self.data('num') + 1;
						_self.data('num', addNum);
						_self.find('p').text(addNum);
						$(this).find("span").addClass("h_selected");
						$(".vote_btn p").each(function(){
							$(this).show(600);//右侧推出显示投票数,速度可控制
						});
					});
				} else {
					if(data.msg.url){
						authorizeRun(data.msg.url);
						return false;
					}
					
					
					showMsg(data.msg, function () {
						$(this).find("span").addClass("h_selected");
						$(".vote_btn p").each(function(){
							$(this).show(600);//右侧推出显示投票数,速度可控制
						});
					});
				}
			}
			, 'json'
		);
	});
	<?php endif; ?>
<?php endif; ?>
	
	
	
	
	

	function refreshVoteBox(isHide) {
		// 隐藏cell
		if (isHide) {
			$(".data_show_cell").fadeOut();
			$(".data_show_cell em").css({width:"0px"});
		}
		
		var cell_lens = {};
		var total = 0;
		
		$(".vt_cell .vt_num").removeClass("vt_num");
		$(".vt_cell").addClass("vt_result_cell");
		
		$(".dv_title").addClass("dv_title_after");//增加投票选项点击后的样式
		$(".data_show_cell em").each(function (i) {
			var num = $(this).data('num');
			cell_lens[i] = num;
			total += num;
		});
		
		var total_vote_num = config_total_vote_num;
		
		$(".data_show_cell").fadeIn();
		$(".data_show_cell em").each(function (i) {
			var perNum = Percentage(cell_lens[i], total_vote_num);
			//$(this).parent().find('b').text(perNum+'%');
			
			$(this).parent().addClass(cell_colors[i-1]);
			var len_num = (cell_lens[i] / total) * 200;
			$(this).animate({width:len_num+"px"},1000);
		});
	}
	
	function showMsg($msg, $callback) {
		$('.tips_close_btn').show();
		$('.vote_result').html($msg);
		$('.a_cover').fadeIn().delay(seconds).fadeOut();
		$('.v_tips_box').fadeIn().delay(seconds).fadeOut(function () {
			if ($callback) $callback();
		});
	}
	
	
	function showLoading() {
		$('.tips_close_btn').hide();
		$('.vote_result').html('加载中..');
		$('.v_tips_box, .a_cover').fadeIn();
	}
	
	$(".tips_close_btn").on('click', function(){
		$(".v_tips_box, .a_cover").hide();
	});
	
	//判断当前页图片加载完成loading消失
	$(".vote_show_box dl dt img").each(function(){
		$(this).load(function(){
			$(this).parent().css("background","none");
		})
	});
	
});
</script>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "bottom.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>