
function initSpinner(){
	//get json data for combo recipe
	var data = {
	  "combo1":{"title":"Guacamole That Rocks","description":"Elevate your guacamole recipe with zesty tomatoes and green chilies.","url":"recipes-Guacamole-That-Rocks-2702.html"},
	  "combo2":{"title":"Queso Burgers","description":"Saturate your burgers with the ultimate cheese sauce.","url":"recipes-Queso-Burgers-2716.html"},
	  "combo3":{"title":"Spicy Black Bean Salsa","description":"Sharpen your salsa with some penetrating picante.","url":"recipes-Spicy-Black-Bean-Salsa-3446.html"},
	  "combo4":{"title":"Simple Taco Salad","description":"Toss your taco salad with our mouthwatering mixture.","url":"recipes-Simple-Taco-Salad-5486.html"},
	  "combo5":{"title":"Ranchero Scrambled Eggs","description":"Whisk some delectable deliciousness into your scramble.","url":"recipes-Ranchero-Scrambled-Eggs-2726.html"},
	  "combo6":{"title":"Zesty Mac & Cheese","description":"Modify your mac and cheese with some snappy sumptuousness.","url":"recipes-Zesty-Mac-and-Cheese-2793.html"},
	  "combo7":{"title":"Kickin' Baked Rigatoni","description":"Shift your pasta into gear with some tempting tomatoes and chilies","url":"recipes-Kickin-Baked-Rigatoni-2703.html"},
	  "combo8":{"title":"Beefy Cowboy Chili","description":"Turn your chili into a champion with some robust zestiness.","url":"recipes-Beefy-Cowboy-Chili-2540.html"},
	  "combo9":{"title":"Easy Chicken Fajitas","description":"Perk up your fajitas with some scrumptious goodness.","url":"recipes-Easy-Chicken-Fajitas-5485.html"},
	  "combo10":{"title":"Creamy Chicken Tortilla Soup","description":"Rev up your tortilla soup with savory tomatoes and green chiles.","url":"recipes-Creamy-Chicken-Tortilla-Soup-3321.html"},
	  "combo11":{"title":"Queso Potato","description":"Dress your baked potato jackets up with a dab of zesty deliciousness.","url":"recipes-Queso-Potato-2719.html"} 
	}
	
	// init slots
	$('.slot').each( function(){
		var currentList = $(this)
		var firstItem = currentList.children('li:first')
		var myList = currentList.children('li')
		myList.clone().appendTo( currentList ) // create one set of clone
		myList.clone().appendTo( currentList ) // create another set
		var itemCount = currentList.children().length // number of spinner items
		var myNum = randomRange(itemCount/3, (itemCount/3)*2)
		var listHeight = -( (firstItem.outerHeight() * myNum)-firstItem.outerHeight() )
		currentList.css('top',listHeight)
	})
	
	isPlaying = false
	
	// function to control flash via js //
	function playClickSound()
	{
		$('#fl').externalInterface({
			method:'playSound1',
			success: function(response){},
			error: function(error){}
		});
	}
	
	function playSound2()
	{
		$('#fl').externalInterface({
			method:'playSound2',
			success: function(response){},
			error: function(error){}
		});
	}
	function playSound3()
	{
		$('#fl').externalInterface({
			method:'playSound3',
			success: function(response){},
			error: function(error){}
		});
	}
	function playSound4()
	{
		$('#fl').externalInterface({
			method:'playSound4',
			success: function(response){},
			error: function(error){}
		});
	}
	
	
	
	function playSlots() {
		isPlaying = true;
		finishedCount = 0;
		var totalCombi = 11;
		var xx = [];
		
		// rig the slot
		function generateResult(){
			var combi = randomRange(1, totalCombi );
			
			if (combi == 1)      {xx[1] = 2; xx[2] = 3; xx[3] = 1; xx['title'] = data.combo1.title; xx['desc'] = data.combo1.description; xx['url'] = data.combo1.url; }
			else if (combi == 2) {xx[1] = 4; xx[2] = 5; xx[3] = 1; xx['title'] = data.combo2.title; xx['desc'] = data.combo2.description; xx['url'] = data.combo2.url; }
			else if (combi == 3) {xx[1] = 7; xx[2] = 6; xx[3] = 1; xx['title'] = data.combo3.title; xx['desc'] = data.combo3.description; xx['url'] = data.combo3.url; }
			else if (combi == 4) {xx[1] = 8; xx[2] = 5; xx[3] = 1; xx['title'] = data.combo4.title; xx['desc'] = data.combo4.description; xx['url'] = data.combo4.url; }
			else if (combi == 5) {xx[1] = 10; xx[2] = 9; xx[3] = 1; xx['title'] = data.combo5.title; xx['desc'] = data.combo5.description; xx['url'] = data.combo5.url; }
			else if (combi == 6) {xx[1] = 11; xx[2] = 4; xx[3] = 1; xx['title'] = data.combo6.title; xx['desc'] = data.combo6.description; xx['url'] = data.combo6.url; }
			else if (combi == 7) {xx[1] = 13; xx[2] = 12; xx[3] = 1; xx['title'] = data.combo7.title; xx['desc'] = data.combo7.description; xx['url'] = data.combo7.url; }
			else if (combi == 8) {xx[1] = 14; xx[2] = 5; xx[3] = 1; xx['title'] = data.combo8.title; xx['desc'] = data.combo8.description; xx['url'] = data.combo8.url; }
			else if (combi == 9) {xx[1] = 15; xx[2] = 1; xx[3] = 16; xx['title'] = data.combo9.title; xx['desc'] = data.combo9.description; xx['url'] = data.combo9.url; }
			else if (combi == 10) {xx[1] = 16; xx[2] = 1; xx[3] = 6; xx['title'] = data.combo10.title; xx['desc'] = data.combo10.description; xx['url'] = data.combo10.url; }
			else if (combi == 11) {xx[1] = 17; xx[2] = 1; xx[3] = 4; xx['title'] = data.combo11.title; xx['desc'] = data.combo11.description; xx['url'] = data.combo11.url; }
			//alert (xx)
			return xx;
		}
		generateResult()
		
		slotNumber = $('.slot').length
		$('.slot').each( function(){
			var currentList = $(this)
			var currentListClass = $(currentList).attr('id')
			var firstItem = currentList.children('li:first')
			var myList = currentList.children('li')
			var itemCount = currentList.children().length
			var myNum = randomRange(itemCount/3, (itemCount/3)*2)
	
			var listHeight = -( firstItem.outerHeight() * ( itemCount/3))*2
			var zz = randomRange(2,4)
			var spinSpeed = 100 * zz
			var adjSpin = randomRange(500,800);
			
			function lowerSpeed() {
				//alert(adjSpin + ' || ' + currentListClass)
				if ( spinSpeed < adjSpin ) {
					//var yyy = randomRange(1,3)
					spinSpeed += 50;//spinSpeed*(yyy/10)
					doSpin()
				} else {
					
					//rig the machine
					if (currentListClass == 'sl01'){ myNum = xx[1] + (itemCount/3)}
					else if (currentListClass == 'sl02'){myNum = xx[2] + (itemCount/3)}
					else if (currentListClass == 'sl03'){myNum = xx[3] + (itemCount/3)}
					else {myNum = myList.length} // no data
					
					var itemID = myNum
	
					var finalPos = - ( (firstItem.outerHeight() * myNum)-firstItem.outerHeight() )
					var finalSpeed = ((spinSpeed*.5)* (itemCount/3)) /  (myNum-(itemCount/3))
					
					if (myNum < (itemCount/3)+3) {
						finalSpeed = ((spinSpeed*.15)* (itemCount/3)) /  (myNum-(itemCount/3))
					} 
					//var finalSpeed = ( (spinSpeed * .5) * (itemCount/3) ) / myNum				
					
					
					
					function checkSpinState() {
						finishedCount++
						if (slotNumber > $('.slot').length) {
							slotNumber = $('.slot').length
						}
						
						if (finishedCount == slotNumber) {
							//when done spinning all spinners
							isPlaying = false
							
							// play win Sound
							//playWinSound()
							
							//flash bg
							var bgbg = $('#rouletteWrap #rouletteContent').css('background-image');
							$('#rouletteWrap #rouletteContent').css('background-image','none');
							$('#rouletteWrap .bg-flash-fx').fadeIn(75).fadeOut(75).fadeIn(75).fadeOut(75).fadeIn(75).fadeOut(75, function(){$('#rouletteWrap #rouletteContent').css('background-image',bgbg);});
							
							
							//place data
							$('#rouletteContent span.recipeTitle').html(xx['title'])
							$('#rouletteContent p.result').html(xx['desc'])
							$('#rouletteContent a.btnRecipe').attr('href',xx['url'])
							
						}
						//do something when each of the spinner is finished
						/*
						if (currentListClass == 'sl01'){playSound2()}
						else if (currentListClass == 'sl02'){playSound3()}
						else if (currentListClass == 'sl03'){playSound4()}
						*/
						
						//play do-re-mi
						switch(finishedCount){
							 case 1:
							 playSound2();
							 break;
							 case 2:
							 playSound3();
							 break;
							 case 3:
							 playSound4();
							 break;
						}
					}
					
					// last spin
					currentList.css('top',listHeight).animate( {'top': finalPos+(firstItem.outerHeight()/32)}, finalSpeed, 'swing').animate( {'top': finalPos}, (spinSpeed*.3)*(itemCount/3)/myNum, 'easeOutBack', checkSpinState)
					
				}
			}
			
			function doSpin() {
				// spin cycle
				var listHeight2 = -( firstItem.outerHeight() * ( itemCount/3))
				currentList.css('top',listHeight).animate( {'top':listHeight2}, (spinSpeed*.4000), 'linear', lowerSpeed )
			}
			
			// start spinning
			doSpin();	
		});
	}
	
	
	$('.btnSpin').click(function(event){
		event.preventDefault();
		if (!isPlaying) {
			playClickSound();
			setTimeout(playSlots,100);
		} else {
			//do nothing
		}
	})
	
	$(window).load( // when all elements are loaded
		function() {
			if (!window.location.hash){
			  setTimeout(function(){$('.btnSpin').trigger('click');}, 800);
			} else {
			  if (!isPlaying) {
			    $('a.video').trigger('click');
			  }
			}
		}
	);
}

