
var aniloop = 0;
var index = 0;
var images1;
var images2;
var images3;
var images4;
var rand1;
var rand2;
var rand3;
var rand4;
var stuckcnt = 0;
var aniwheel;
var stat = false;

function loadSlot() {
	
	//alert('loading slot');
	//var slotshow = document.getElementById("slotshow");
	//slotshow.style.visibility = 'visible';
	boy = new Image();
	boy.src = "/images/slotter/boy.gif"
	boy_henry = new Image();
	boy_henry.src = "/images/slotter/boy_henry.gif"
	boy_girl = new Image();
	boy_girl.src = "/images/slotter/boy_girl.gif"
	boy_sam = new Image();
	boy_sam.src = "/images/slotter/boy_sam.gif"
	
	henry = new Image();
	henry.src = "/images/slotter/henry.gif"
	henry_boy = new Image();
	henry_boy.src = "/images/slotter/henry_boy.gif"
	henry_girl = new Image();
	henry_girl.src = "/images/slotter/henry_girl.gif"
	henry_sam = new Image();
	henry_sam.src = "/images/slotter/henry_sam.gif"
	
	sam = new Image();
	sam.src = "/images/slotter/sam.gif"
	sam_boy = new Image();
	sam_boy.src = "/images/slotter/sam_boy.gif"
	sam_girl = new Image();
	sam_girl.src = "/images/slotter/sam_girl.gif"
	sam_henry = new Image();
	sam_henry.src = "/images/slotter/sam_henry.gif"
	
	girl = new Image();
	girl.src = "/images/slotter/girl.gif"
	girl_boy = new Image();
	girl_boy.src = "/images/slotter/girl_boy.gif"
	girl_henry = new Image();
	girl_henry.src = "/images/slotter/girl_henry.gif"
	girl_sam = new Image();
	girl_sam.src = "/images/slotter/girl_sam.gif"
	
	images1 = new Array(boy, boy_henry, henry, henry_sam, sam, sam_girl, girl, girl_boy);
	images2 = new Array(henry, henry_boy, boy, boy_sam, sam, sam_girl, girl, girl_henry);
	images3 = new Array(sam, sam_girl, girl, girl_henry, henry, henry_boy, boy, boy_sam);
	images4 = new Array(girl, girl_sam, sam, sam_boy, boy, boy_henry, henry, henry_girl);
				
	//initAnimate();

}



function initAnimate() {

	var slotshow = document.getElementById("slotshow");
	slotshow.style.visibility = 'visible';
	
	if( stat ) {
		//alert( stat );
		return;
	}
	index = 0;
	aniloop = 0;
	stuckcnt = 0;
	rand1 = rand(4);
	rand2 = rand(4);
	rand3 = rand(4);
	rand4 = rand(4);
	aniwheel = "";
	//alert("images" + rand1 + "[index].src");
	//alert( stat );
	stat = true;
	animateSlot();
}

function animateSlot() {
	
	var sleep = 20;
	index++;
	if (index == 8) {
		aniloop++;
		index = 0;
	}
	
	if(aniloop < 5) {
		//alert( aniloop );
		if(aniloop == 4 && index > 2) {
			sleep = 100;
		}
		setTimeout("animateSlot()", sleep);
		eval("document.images['one'].src = images" + rand1 + "[" + index + "].src"); //images1[index].src;
		document.images["two"].src = eval("images" + rand2 + "[index].src");
		document.images["three"].src = eval("images" + rand3 + "[index].src");
		document.images["four"].src = eval("images" + rand4 + "[index].src");	
	} else {
		document.images["one"].src = eval("images" + rand1 + "[0].src");
		document.images["two"].src = eval("images" + rand2 + "[0].src");	
		document.images["three"].src = eval("images" + rand3 + "[0].src");
		document.images["four"].src = eval("images" + rand4 + "[0].src");	
		
		stuck();		
	}
	return 1;

}

function stuck() {
	aniwheel = 'one';
	if(rand1 == 2) {
		aniwheel = 'two';
	} else if (rand1 == 3) {
		aniwheel = 'three';
	} else if(rand1 == 4) {
		aniwheel = 'four';
	}
	stuckAni();		
}

function stuckAni() {
	if(stuckcnt < 4) {
		stuckcnt++;
		//alert("document.images[" + aniwheel + "].src");
		document.images[ aniwheel ].src = eval("images" + rand1 + "[stuckcnt].src");
		setTimeout("stuckAni()", 100);
	} else {
		document.images[ aniwheel ].src = eval("images" + rand1 + "[0].src");
		//alert(stat);
		if( document.images["one"].src == document.images["two"].src 
			&& document.images["one"].src == document.images["three"].src
			&& document.images["one"].src == document.images["four"].src ) {
			alert('YOU WIN! To receive a prize, email the secret code word to winner@jsworldwide.com to receive a free prize! The secret code words is: "cheeselips." Now go tell your friends you are a real winner.');
		}
		stat = false;
	}
}


rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};


