<?php if(!isset($sumfingIncl)) {header("HTTP/1.0 403 Forbidden"); die();} ?>
<script type="text/javascript">
jQuery( document ).ready(function() {
	
	$('#roll_L,#roll_C,#roll_R').hide();
	$('#single_heart_L,#single_clover_C,#single_star_R').fadeIn(500);
	
	$('#collect_btn').click(function() {
		
		<?php 
		//Collect without facebook post	
		if(!isset($set->slot_timeline_toggle)) { ?>
		
		$(this).html('<?php echo _("Zzzz...");?>');
		// Post to actions
		$.post("slot_actions.php", { "func": "collect","user_id": "<?php echo $userdata->fake_id;?>" },
  		function(data){
			if(data.ok == 1) {
				$('#collect_btn').html('<?php echo _("Done!");?>');
				setTimeout( function() {
					top.location.href= '<?php echo MY_APP_URL;?>'; 
				},1000);
			}
		},"json");
		<?php } else {
		// Collect with timeline posting
		
		?>
		$(this).html('<?php echo _("Posting...");?>');
		var title =   '<?php echo str_replace("'","\'",$set->slot_msg_title);?>'//#wins
		title = title.replace('[AMOUNT]', $('#wins').text());
		FB.ui({
		  method: 'feed',
		  link: '<?php echo MY_APP_URL;?>',
		  picture: '<?php echo $app_files_url.'/uploads/'.$set->slotmsg_img;?>',
		  name: title,
		  caption: '<?php echo str_replace("'","\'",$set->slot_msg_caption);?>',
		  description: '<?php echo str_replace("'","\'",$set->slot_msg_description);?>'
		}, function(response){
				if(response) {
					
					$.post("slot_actions.php", { "func": "collect","user_id": "<?php echo $userdata->fake_id;?>" },
					function(data){
						if(data.ok == 1) {
							$('#collect_btn').html('<?php echo _("Thanks!");?>');
							setTimeout( function() {
								top.location.href= '<?php echo MY_APP_URL;?>'; 
							},1500);
						}
					},"json");
					
				} else {
					$('#collect_btn').html('<?php echo _("Collect");?>');
				}
		   });
		
		<?php }?>
		
	});
	
	// Collect tickets with facebook posting
	
	
	// Spin
	$("#spin_btn").click(function() {
		
		$(this).hide();
		$('#spin_btn_ph').show().attr("disabled", true);
		
		connection_timeout = setTimeout( function() {
			$('#roll_L,#roll_C,#roll_R').hide();
			$('#single_heart_L,#single_clover_C,#single_star_R').fadeIn(500);
			alert('<?php echo  _("No connection!");?>');
		},10000 );
		
		$('.single_items').hide();
		$('#roll_L,#roll_C,#roll_R').show();
			
		// Post to actions
		$.post("slot_actions.php", { "func": "getWheels","user_id": "<?php echo $userdata->fake_id;?>" },
  		function(data){
			if(data.wheel3 != "") {
				clearTimeout(connection_timeout);
			}
			setTimeout( function() {
				$('#roll_L').hide();
				$("#single_"+data.wheel1+"_L").show().appendTo("#single_L");
			},1000 );
			setTimeout( function() {
				$('#roll_C').hide();
				$("#single_"+data.wheel2+"_C").show().appendTo("#single_C");
				
				if(data.wheel1 == data.wheel2) {
					$("#single_"+data.wheel1+"_L,#single_"+data.wheel2+"_C").hide();
					$("#single_"+data.wheel1+"_L_win").show().appendTo("#single_L");
					$("#single_"+data.wheel2+"_C_win").show().appendTo("#single_C");
				}
			},1800 );
			
			setTimeout( function() {
				$('#roll_R').hide();
				$("#single_"+data.wheel3+"_R").show().appendTo("#single_R");
				
				if(data.wheel1 == data.wheel2 && data.wheel2 == data.wheel3) {
					$("#single_"+data.wheel3+"_R").hide();
					$("#single_"+data.wheel3+"_R_win").show().appendTo("#single_R");
				}
				
				if(data.win == 0) {
					$("#single_"+data.wheel1+"_L_win,#single_"+data.wheel2+"_C_win,#single_"+data.wheel3+"_R_win").hide();
					$("#single_"+data.wheel1+"_L,#single_"+data.wheel2+"_C,#single_"+data.wheel3+"_R").show();
				}
				
				if(data.win != 0) {
					$("#lastwin").show();
					$("#latestwin").text(data.win);
					$("#wins").removeClass('btn-inverse').addClass('btn-info');
					setTimeout( function() {
					$("#wins").removeClass('btn-info').addClass('btn-inverse');
				},1000 );
					//alert(data.win);
				}
				$('#spin_btn_ph').hide();
				$("#spin_btn").show();
				$("#spins_left").text(data.spinsleft);
				$("#wins").text(data.win_total);
				
				if(data.spinsleft == 0) {
					$('#spin_btn').hide();
					if(data.win_total != 0) {
						$('#collect_btn').show();
						<?php if(isset($set->slot_timeline_toggle)) {?>
						$('#explain_post').show();
						<?php }?> 
					} else {
						$('#back_btn,#no_win').show();
					}
				}
			},3000 );
    
  		}, "json");
		
	});
});

</script>