<!-- // STORYSTARTER FRUIT MACHINE JAVASCRIPT CODE
var spinlocked = false;
var numbuttons = 4;
var totalgenres=4;
var debug=false;

// Total number of genres selected at any one time
var maxgenres = numbuttons;
// Total available genres (4)

imggenreson=new Array(totalgenres-1);
imggenresoff=new Array(totalgenres-1);

imggenreson[0]=new Image();
imggenreson[0].src="genre0_on.gif";

imggenreson[1]=new Image();
imggenreson[1].src="genre1_on.gif";

imggenreson[2]=new Image();
imggenreson[2].src="genre2_on.gif";

imggenreson[3]=new Image();
imggenreson[3].src="genre3_on.gif";

imggenresoff[0]=new Image();
imggenresoff[0].src="genre0_off.gif";

imggenresoff[1]=new Image();
imggenresoff[1].src="genre1_off.gif";

imggenresoff[2]=new Image();
imggenresoff[2].src="genre2_off.gif";

imggenresoff[3]=new Image();
imggenresoff[3].src="genre3_off.gif";

var hold_on =new Image();
hold_on.src="hold_on.gif";

var hold_off =new Image();
hold_off.src="hold_off.gif";


ii = new Image();
ii.src='spinlit.gif';

iii = new Image();
iii.src='collectlit.gif';

iiii = new Image();
iiii.src='nudgelit.gif';

// reels [plotelement ] [genre] [instance]

reels = new Array(numbuttons);
for (plot_el=0; plot_el < numbuttons; plot_el++) {
	reels[plot_el]=new Array();
	for (genre=0; genre<numbuttons; genre++) {
		reels [plot_el] [genre ] =new Array();
		}
	}

// 0 = horror - 1 = sc i fi - 2= real life - 3 =  love story
// Heroes
reels[0][0][0] = "vampire";
reels[0][0][1] = "vampire slayer";
reels[0][0][2] = "mad axeman";
reels[0][0][3] = "poltergeist";
reels[0][0][4] = "rat";
reels[0][0][5] = "murderer";
reels[0][0][6] = "ghost";
reels[0][0][7] = "werewolf";
reels[0][0][8] = "killer bees";
reels[0][0][9] = "zombie";
reels[0][0][10] ="cyclops";

reels[0][1][0] = "spaceship captain";
reels[0][1][1] = "hostile alien";
reels[0][1][2]="alien warlord";
reels[0][1][3]="artificial intelligence program";
reels[0][1][4]="computer hacker";

reels[0][2][0] ="grandad";
reels[0][2][1] ="reporter";
reels[0][2][2] ="dinner lady";
reels[0][2][3]="angler";
reels[0][2][4]="bully";
reels[0][2][5]="burglar";
reels[0][2][6]="careers officer";
reels[0][2][7]="homeless person";
reels[0][2][8]="little sister";
reels[0][2][9]="parent";
reels[0][2][10]="person crying";
reels[0][2][11]="person fighting";
reels[0][2][12]="police officer";
reels[0][2][13]="pub landlady";
reels[0][2][14]="shoplifter";
reels[0][2][15]="trainspotter";


reels[0][3][0] = "princess";
reels[0][3][1] = "soldier";
reels[0][3][2]="boss of the company";
reels[0][3][3]="Captain of the football team";
reels[0][3][4]="cheerleader";
reels[0][3][5]="doctor (male or female)";
reels[0][3][6]="girl wearing glasses";
reels[0][3][7]="great dancer";
reels[0][3][8]="nurse (male or female)";
reels[0][3][9]="boy/girl next door";
reels[0][3][10]="pop star";
reels[0][3][11]="siblings' partner";
reels[0][3][12]="very nervous person";

// 0 = horror - 1 = sc i fi - 2= real life - 3 =  love story

// Locations
reels[1][0][0] = "haunted house";
reels[1][0][1] = "morgue";
reels[1][0][2]="ancient castle";
reels[1][0][3]="dark alley at night";
reels[1][0][4]="deep well";
reels[1][0][5]="deserted warehouse";
reels[1][0][6]="Eastern European Country";
reels[1][0][7]="graveyard";
reels[1][0][8]="locked bedroom";
reels[1][0][9]="prison cell";
reels[1][0][10]="psychiatric ward";
reels[1][0][11]="vast forest";
reels[1][0][12]="wardrobe";

reels[1][1][0] = "spaceship";
reels[1][1][1] = "mysterious planet";
reels[1][1][2]="computer game";
reels[1][1][3]="computer room";
reels[1][1][4]="different world";

reels[1][2][0] = "old people's home";
reels[1][2][1] = "school";
reels[1][2][2]="bathroom";
reels[1][2][3]="car on the motorway";
reels[1][2][4]="city centre";
reels[1][2][5]="football ground";
reels[1][2][6]="hospital";
reels[1][2][7]="India";
reels[1][2][8]="library";
reels[1][2][9]="Living room";
reels[1][2][10]="London";
reels[1][2][11]="police station";

reels[1][3][0] = "palace";
reels[1][3][1] = "lonely moor";
reels[1][3][2]="bedroom";
reels[1][3][3]="cinema";
reels[1][3][4]="coffee shop";
reels[1][3][5]="Ibiza holiday resort";
reels[1][3][6]="New York";
reels[1][3][7]="nightclub";
reels[1][3][8]="pub";
reels[1][3][9]="supermarket";
reels[1][3][10]="the executive boardroom";
reels[1][3][11]="the Palace";
reels[1][3][12]="the park";

// 0 = horror - 1 = sc i fi - 2= real life - 3 =  love story

// Quests
reels[2][0][0] = "slay the monster";
reels[2][0][1] = "decipher an inscription";
reels[2][0][2]="drink a potion";
reels[2][0][3]="escape";
reels[2][0][4]="exorcise demons";
reels[2][0][5]="find someone";
reels[2][0][6]="keep sane";
reels[2][0][7]="kill the enemy";
reels[2][0][8]="save the family";
reels[2][0][9]="survive";
reels[2][0][10]="uncover a con trick";

reels[2][1][0] = "refuel the ship";
reels[2][1][1] = "cure an alien virus";
reels[2][1][2]="create a healthier atmosphere";
reels[2][1][3]="discover who is a real person";
reels[2][1][4]="discover your opponent's weakness";


reels[2][2][0] = "find false teeth";
reels[2][2][1] = "teach a difficult lesson";
reels[2][2][2]="buy a birthday present";
reels[2][2][3]="decide where to go on holiday";
reels[2][2][4]="eat a horrible meal";
reels[2][2][5]="find something";
reels[2][2][6]="fix something broken";
reels[2][2][7]="get back home";
reels[2][2][8]="get better";
reels[2][2][9]="get on TV";
reels[2][2][10]="get some money";
reels[2][2][11]="get to work on time";
reels[2][2][12]="pass an exam";
reels[2][2][13]="pass on some bad news";
reels[2][2][14]="win the pub quiz";

reels[2][3][0] = "elope";
reels[2][3][1] = "persuade the father to permit marriage";
reels[2][3][2]="ask someone for a date";
reels[2][3][3]="ask someone to marry you";
reels[2][3][4]="dance with the person you love";
reels[2][3][5]="deal with a two-timing lover";
reels[2][3][6]="get someone to admit they love you";
reels[2][3][7]="get to the church on time";
reels[2][3][8]="identify a blind date";
reels[2][3][9]="kiss under the mistletoe";
reels[2][3][10]="steal your friend's partner";

// Key item
reels[3][0][0] = "enchanted amulet";
reels[3][0][1] = "silver bullet";
reels[3][0][2]="book written in a strange language";
reels[3][0][3]="Colt 45 revolver";
reels[3][0][4]="crucifix";
reels[3][0][5]="disconnected  telephone";
reels[3][0][6]="handcuffs";
reels[3][0][7]="hypodermic syringe";
reels[3][0][8]="key";
reels[3][0][9]="clove of garlic";
reels[3][0][10]="spade";

reels[3][1][0] ="ray gun";
reels[3][1][1] ="leaking fuel container";
reels[3][1][2]="floppy disk";
reels[3][1][3]="genetically modified organism";
reels[3][1][4]="hot cup of tea";

reels[3][2][0] = "hearing aid";
reels[3][2][1] = "old photographs";
reels[3][2][2]="five pound note";
reels[3][2][3]="hamburger";
reels[3][2][4]="handbag";
reels[3][2][5]="hat";
reels[3][2][6]="mobile phone";
reels[3][2][7]="newspaper";
reels[3][2][8]="pair of shoes";
reels[3][2][9]="television";
reels[3][2][10]="ticket";
reels[3][2][11]="toothbrush";


reels[3][3][0] = "gold ring"
reels[3][3][1] = "handkerchief";
reels[3][3][2]="birthday card";
reels[3][3][3]="box of chocolates";
reels[3][3][4]="favourite shirt";
reels[3][3][5]="holiday";
reels[3][3][6]="letter";
reels[3][3][7]="message on answering machine";
reels[3][3][8]="photograph";
reels[3][3][9]="red rose";
reels[3][3][10]="perfume";
reels[3][3][11]="silver necklace";
reels[3][3][12]="text message";


// Zero the current genre and current selection on each reel (necessary to track these variables for nudge to work)
currgenres =new Array();
currselections= new Array();
for(reel=0; reel< reels.length; reel++){
currgenres [reel]=0;
currselections[reel]=0;
	}



function nudge(reel){
availableselections=reels [reel] [ currgenres[reel] ].length;
currselections[reel]=currselections[reel]+1;
if ( currselections[reel] >= availableselections ){
	incrementgenre(reel)
	}
validategenre(reel);
document.machine[reel].value=reels[reel][currgenres[reel] ] [currselections[reel] ];
}

function incrementgenre(reel){
// advance the current genre of the reel to the next on the ring ...
currselections[reel]=0;
currgenres[reel]=currgenres[reel]+1;
if (currgenres[reel]>=maxgenres){
	currgenres[reel]=0;
	}
currselections[reel]=0
//...and select the the first element of the new genre to produce smooth nudging
return currgenres[reel];
}

function randomise_element(reel){
elementmax=reels[reel][currgenres[reel]].length-1;
randelement=randnum(elementmax);
currselections[reel]=randelement;
return randelement;
}

function validategenre(reel){
var reelgenre=currgenres[reel];

// Find the first available genre on the given reel

genrebuttonimg="genre" + reelgenre;
while (document[genrebuttonimg].src == imggenresoff[reelgenre].src) {

	reelgenre=incrementgenre(reel);

	genrebuttonimg="genre"+reelgenre;
	}
}


function togglehold(index) {

imgname= "hold"+index
if (document[imgname].src == hold_off.src) 	{
	document[imgname].src=hold_on.src;
						}
				else 	{
	    document[imgname].src=hold_off.src
						}
}

function togglegenre(index) {
imgname= "genre"+index
if ( (document[imgname].src == imggenreson[index].src) && (totalgenres<2) ) 	{
alert("You're not allowed to turn off all the genres.");
return 0;
}

if ( document[imgname].src ==imggenreson[index].src  ) 	{
	document[imgname].src=imggenresoff[index].src;
	totalgenres=totalgenres-1;
						}
				else	{
	document[imgname].src=imggenreson[index].src;
	totalgenres=totalgenres+1;
						}

}


function spinrepeat(){
spin();
setTimeout('spin()',5);
setTimeout('spin()',10);
setTimeout('spin()',30);
setTimeout('spin()',70);
setTimeout('spin()',150);
setTimeout('spin()',310);
setTimeout('spin()',630);
setTimeout('spin()',1000)
}

function spin(){

if (spinlocked==true) {
 return
	}
for (x=0; x<numbuttons; x++) {
	imgname= "hold"+x
	if (document[imgname].src == hold_off.src) 	{
	spinreel(x)
		}
	}
}

function randnum(max){
// returns an integer from 0 to max inclusive
var returnval;
returnval=Math.floor(Math.random()*(max+1));

return returnval;
}

function spinreel(index){

reelname= "displayreel"+index;
genremax=reels [index].length-1;
randgenre=randnum(genremax);
elementmax=reels[index][randgenre].length-1;
randelement=randnum(elementmax);
currgenres[index]=randgenre;
currselections[index]=randelement;
// alert("genremax is "+genremax);
// alert("elementmax is "+elementmax);

nudge(index);
currselections[index]=randomise_element(index);
// neccessary because nudging causes bunching on the first element of the first free genre
nudgedgenre=currgenres[index];
nudgedelement=currselections[index];

document.machine[reelname].value=reels[index][nudgedgenre][nudgedelement];
document.machine[0].value
	}

function flashbuttons(){
spinlocked=true;
setTimeout('spinlocked=false', 1100)
	for(x=0; x<10; x++) {
		for(i=0; i<numbuttons; i++) {
		setTimeout('togglehold('+i+')',(x*100)+(i*15))
		}
	}

}

function collect(){

var report ="<HTML><HEAD><TITLE>story starting point</TITLE></HEAD>" +
"<BODY BGCOLOR='#FFFFFF'><FONT SIZE=+2>Story starting point</FONT><p>"

+"<HR> Principal character of the story: <B> "
+ document.machine.displayreel0.value

+"</B> <BR> <i>Will this be the hero or villain? Will they narrate the story, in a first person narrative?</i>"

+"<HR> Main location of the story : <B>"
+ document.machine.displayreel1.value

+"</B><BR><i>Will the story begin or end here? Will there be other locations?</i>"

+"<HR> The main problem that has to be solved in the story: to <B> "
+ document.machine.displayreel2.value

+"</B><BR> <i>Are there other problems to solve? Will it be solved at the end, to create closure in your story?</i>"

+"<HR>Key item in the solution to this problem: <B>"
+ document.machine.displayreel3.value
+"</B><BR> <i>Will this be a help or a hindrance? Is it something that has to be found?</I>"

+'<BR><FORM><TABLE BORDER=1><TR><TD><INPUT TYPE="BUTTON" VALUE="Print" onClick="window.print();">&nbsp;<INPUT TYPE="button" NAME="button1" VALUE="close" onClick="self.close()"></TD><TD><FONT SIZE=-1>If you have problems with the print button, copy this text (Windows users: select the text and press CTRL C). Then paste the text into a word processor document. </FONT></TD></TR></TABLE></FORM>'
+"</FONT></BODY></HTML>";

reportwin=window.open("", "reportwin", "width=450,height =500,resizable=yes,scrollbars=no,status=no");
reportwin.document.write(report);
reportwin.document.close();
}
// -->

