 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
		<html lang="en">
		<meta charset="utf-8">
  		<title>Spin & Win</title>
  		<meta name="description" content="Spin & Win">
  		<meta name="author" content="Anything Graphic">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<head>
		<!-- We need to load this version of jQuery because it is compatible with the Slot Machine and Star Review scripts -->
	 	<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'></script>
	  	<!-- The next three scripts are for the Slot Machine --> 
	  	<script src='boomtag{boomtime_path}/script/jquery.spritely.js'></script>
	 	<script src='boomtag{boomtime_path}/script/jquery.backgroundPosition.js'></script>
	  	<script src='boomtag{boomtime_path}/script/slot.js'></script>
	  	<!-- Star review script -->
	  	<script src='boomtag{boomtime_path}/script/jquery.raty.min.js'></script>
		</head>
		<body>
 <!-- [if lt IE 9]>
	  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	  <![endif]-->
	   <script type="text/javascript">

		$(function() {

			//added this script for firefox support to remove disabled 
			//attribute in text and submit button once you click the back button after form submit and you hit refresh
			$("#email-submit").attr('disabled', false);
			$("#email_add").attr('disabled',false);

			if($("#email_add").val() == '')
				setTimeout(this.preStartSlotMachine, 1000);

			//validate Email Address
			function validateEmail($email) {
			  	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			  	if( !emailReg.test( $email ) ) {
			    	return false;
			  	} else {
			    	return true;
			  	}
			}

			//Play the slot machine when the email is submitted
			$("#email-submit").click(function(){

				$("#err_msg").html('');
				$('#jackpot').fadeOut('fast');
				$('.slot-wrapper').fadeTo( "fast", 1 );

				if(!$("#email_add").val()) {
					$("#err_msg").html("* Please enter your email address.");
					return false;
				} else if( !validateEmail($("#email_add").val())){
					$("#err_msg").html("* Please enter a valid email address. For example <b><i>johnsmith@gmail.com</i></b>");
					return false;
			    } else {

					$("#email-submit").attr('disabled', true);
					$("#email_add").attr('disabled',true);
					$("button#control").click();

					//get start time of running ajax;
					var start_time = new Date().getTime();

					
					$.ajax({
						url: '/slot-machine',
					 	type: "POST",
					  	dataType: "json",
					  	data: { 
					  		id : 'play_slot',
					  		email: $('#email_add').val(),
					  		referred_org: 'boomtag{org_business_client_email}'
					  	},
					  	success: function(data){

					  		slot_callback = false;
					  		//get the ajax processing time.. 
					  		var request_time = new Date().getTime() - start_time;
					  		//if ajax processing time is less than 3 seconds.. put a delay of 3 seconds before slot machine stops.
					  		var delay_time = (request_time < 3000) ? 3000 - request_time : 0;

					  		var success = true;

					  		if(data[0] == "error")
					  		{
					  			$('#won_msg').text('Sorry!');
					  			$('#offer').text('No prizes available.');
					  			$('#prize_info').text('Prize Info: Sorry no email was sent.');
					  			success = false;
					  		}
					  		else if(data[0] == 'exist')
					  		{
					  			$('#won_msg').text('Sorry, only one spin per email address.');
					  			$('#offer').text('');
					  			$('#prize_info').text('');
					  			success = false;
					  		}

					  		if(!success) {
					  			//callback function if email already exists or if there are no prizes available.
					  			slot_callback = function() {
					  				$('#control').text('Start');
					  				$('#jackpot').fadeIn('fast');
									$('.slot-wrapper').fadeTo( "slow", 0.33 );
									$("#email-submit").attr('disabled', false);
									$("#email_add").attr('disabled',false);
					  			};

					  			setTimeout(function() {
						  			$("button#control").click();
					  			}, delay_time);

					  			return false;
					  		} else {

						  		//callback function for successful slot machine game..
								slot_callback = function(){
									$('#won_msg').text('You’ve Won!');
									$('#offer').text(data[0]);
					  				$('#org_client').val(data[1]);
									$('#page-title').text('Congratulations').after('<p>You will be redirected to your prize in a moment.</p>');	

									var send_data = {};
									send_data.prize = data[0];
						  			send_data.client_id = data[1];

									var frm = document.createElement("form");
										frm.method = "post";
											send_data.main_org = 'boomtag{main_org}';
											frm.action = 'boomtag{main_org_claim_prize}';
									var input = document.createElement("input");
										input.type="hidden";
										input.name="data";
										input.value = JSON.stringify(send_data);
										
									frm.appendChild(input);
									document.body.appendChild(frm);

									setTimeout(function() {
										frm.submit();	
									}, 2000);
									
									$('html, body, #wrapper, #container').delay(3600).css('height', 'auto');
					  			};

					  			setTimeout(function() {
	 								$("button#control").click();
	 							}, delay_time);

				  			}
						}
					});
					// ends here
				}
			});

			$('#email_add').focus(this.stopPreSlotMachine).on('keyup', this.stopPreSlotMachine);
		});
	  </script>
<div id="wrapper">
  <div id="container" style='background:none repeat scroll 0 0 boomtag{background_container}'>  	
  	<div class="header row" boomtag{back_image_style}>
  		<div class="inner">
  			 <img id="logo" border="0" src="boomtag{logo}" boomtag{spin_win_logo_visibility} >
  		</div>
  	</div>
  	
  	<div class="row game">
  		<div class="inner">
	  		<h1 id="page-title">boomtag{page_title}</h1>
			<div class="container">
				<div id="jackpot">
					<div class="wrapper">
						<h1 id='won_msg'>YOU’VE WON!!</h1>
						<p id = 'offer'></p>
						<p><small><i id = 'prize_info'>Prize Info: An email with your prize has been sent</i></small></p>
					</div>
				</div>
				<div class="slot-wrapper">
					<div id="slot1" class="slot"></div>
					<div id="slot2" class="slot"></div>
					<div id="slot3" class="slot"></div>
					<div class="clear"></div>
				</div>
				<div><button id="control" style="display:none;">Start</button></div>
			</div>
			<div id="email-address" class="box">
	  			<span id='err_msg' style='color:red;font-size:14px'></span>
		  		<input type="email" placeholder="Email address" id = 'email_add' value="boomtag{business_client_email}">
		  		<input id="email-submit" type="submit" value="Play">
		  	</div>
		  	<p>We need your email to send your prize and other offers.</p>
  		</div>
  	</div> <!-- .row.white -->
	<!--
  	 <div class="row social-media">
  		<div class="inner">
	  		<h2>Follow Us!</h2>
	  		<a href="#" target = "_blank" title="facebook">
	  			<img src="<?= boomtime_path() ?>/img/jslot_images/facebook.png" alt="" />
	  		</a>
	  		<a href="#" title="twitter">
	  			<img src="<?= boomtime_path() ?>/img/jslot_images/twitter.png" alt="" />
	  		</a>
	  		<a href="#" title="google plus">
	  			<img src="<?= boomtime_path() ?>/img/jslot_images/google-plus.png" alt="" />
	  		</a>
	  		<a href="#" title="instagram">
	  			<img src="<?= boomtime_path() ?>/img/jslot_images/instagram.png" alt="" />
	  		</a>
	  		<a href="#" title="pinterest">
	  			<img src="<?= boomtime_path() ?>/img/jslot_images/pinterest.png" alt="" />
	  		</a>
  		</div>
  	</div> 
  -->
  	<div class="row copyright" style="position:relative;">
  		<div class="inner" id="footer_badge">
  			<p>Copyright 2014</p>
  		</div>
  		<a href="http://www.boomtime.com/promotions-tos" id="terms" target ="_blank">Fine print</a>
  	</div>
  </div> <!-- #container -->
</div> <!-- #wrapper -->
<style type="text/css">boomtag{main_css}</style>
</body></html>