// Array of caption sets
var captionSets = new Array (

new Array( // Rockslide megabattle
"Rockslide ahoy!",
"No flying today please",
"Say your last goodbyes grunty",
"It was an accident, honest!",
"I really <em>am</em> a bad cyborg today!",
"Covies nicely drawn my way",
"Heading for the lifeboat corner",
"Time to trigger the dropships",
"Rough indication of part of the dropship trigger area",
"I'm outta here!",

"Out on the mound, and here comes dropship 3. Not long now!",
"Let the good times roll!",
"The best central rock to have; nice and low with great cover on top",
"This sloping design is second best but leaves you very exposed",
"Johnson and Stacker posing outside the rockslide before being horribly killed. Smile boys!",
"Stacker and Johnson dish out some hurt on the Marine plateau",
"Frag out! Stacker lets fly with Johnson in support",
"Johnson, meet Johnson",
"Armoured Aussie extracted from the hillside survivor area, raring to go",
"I don't think this guy will be needing that rifle any more",

"Handy spares for later - these are near the cliffside in the 'far area'",
"Ready to move spares to the plateau",
"Mind if I borrow that blaster?",
"Uh-oh, here comes trouble!",
"Wandering bozo heads into danger",
"Over we go to the island plateau - say hello to your new home",
"Extra Marines for extra bang",
"&quot;It's a mess sir, we're scattered all over this valley&quot;",
"Hold on Stacker, I'm on my way!",
"Hmmm&hellip; so much for stealth!",

"Out of my way you tangerine fool!",
"You'll be safe in here boys",
"Heading in to drop two extras; two more wait in the holding area",
"Four extras dropped on the plateau",
"Eleven bozos wait to be ferried in",
"Squad set up, watching distant Jackals",
"The boys give dropship 3 a warm welcome. Please don't blow yourselves up this time fellas!",
"Arrrgh! And don't blow the cyborg up either, you frag-happy idiots!",
"<em>This</em> lot should give those covies something to think about!",
"Gave 'em a chain-gun to play with too. Oh <em>yeah!</em>",

"Extra hog? Don't mind if I do!",
"Stacker &amp; pals pepper an Elite arriving in the far area. Hee hee! ",
"Say hello to the gang - they're just <em>itching</em> to greet you!",
"Wait here fellas, I've got work to do",
"Island plateau ahead. Outta my way you grunty fool!",
"Pausing near the right entrance to let the covies gather",
"Enemy triggered to move nearer the corner (optional)",
"Here they come; almost done now&hellip;",
"All aboard for fun and games!",
"Pausing at the passage checkpoint",

"Plowing through some of the horde after entry into battle",
"Cyborg comin' through!",
"Entry gap ahead. Hah, missed me with that needler Grunty!",
"Curving left already; no need to get very near the island plateau",
"Roadkill! Grunty goes flying as we head through the island plateau gap",
"Graceful curve around to the gap - with a double-Grunt welcome!",
"Sharp left past the lifeboat, and a plasma-lobbing Grunt",
"Splat! Gap straight ahead&hellip;",
"Dropship 4 Elite located - and tagged!",
"Needles pile in from above, and squid-face isn't best pleased",

"Big fella shapes up for a swipe - but he's gonna miss, ha ha",
"Target sighted! Hold on guys, you may experience a small jolt shortly",
"No, I cannot see out of this bloody visor",
"Narrow escape for something beaky as we head for the top pass",
"I feel this is going to end badly for you, beak-face&hellip;",
"See? I told you",
"&quot;Uhh, I'm hit!&quot; - Johnson takes a plasma ball for the team",
"Yow, that was a <em>close</em> one!",
"Nice design, easy to skim past",
"&quot;Oh yeah!&quot; - Jarring into another design to launch the hog",

"Hah, <em>that'll</em> teach him to look where he's going!",
"This could be messy&hellip;",
"&quot;There's no running!&quot; - Nasty incident heading into the hidey-hole",
"Angling between the trees - and a grunty critter dives clear",
"Stacker gives the covies a warm welcome as we weave left",
"Yeah, you <em>better</em> run Grunty!",
"Ok, that could have gone better",
"Triggers down men, triggers down!",
"You'll need a grenade jump to get up this one",
"Ok, maybe hiding behind Stacker and Johnson wasn't such a good plan after&nbsp;all",

"Take it, squid-face!",
"Parking up at the cliff wall - near some handy spare weapons!",
"<em>Blam!</em> That got him",
"Crouching in the dip and reloading while plasma flies overhead",
"Ok, who's next?",
"Who'll whack first?",
"<em>Bang! Bang!</em> Two with one burst",
"Getting off to an early start",
"Someone's about to get a nasty surprise",
"He doesn't look too happy about that",

"Ok fella, you're next",
"One grunty headshot coming right&nbsp;up",
"Stacker demonstrates how not to avoid a plasma ball, while Johnson has a nice lie down",
"Sheesh! Busy day at the office",
"Gangway! Detouring into the rockslide to release the lifeboat group",
"Johnson extends a warm hand of Marine friendship",
"Oh great, two reds. Time for some rapid shooting!",
"That's right big fella, you're goin'&nbsp;down",
"Will you <em>please</em> stop moving?",
"Think fast or be toast",

"Drilling an Elite while using him as a shield against his buddy",
"Are we having fun yet boys?",
"I'd say you're looking the wrong way buddy",
"Let's see if we can give that Elite a nasty headache&hellip;",
"Say hello to my needler, covie scum",
"Ah, good times&hellip;",
"An early blue Elite gets a nasty peppering from the boys",
"Ok, maybe it's time to lend a hand&nbsp;now",
"Frag out&hellip; times three! I'm standing <em>well</em> clear!",
"He'll never know what hit him",

"Have some of this, squid-face!",
"Aw nuts, there goes half the squad",
"<em>Boom!</em> A well-timed frag blows an arriving blue into a wall of hot lead",
"Dammit Johnson, this is no time to be showing me your dance routine!",
"Drill that airborne Elite!",
"Ok, there's good news and there's bad news",
"A Marine at the back of the plateau proves his worth with an impressive triple-Grunt fragging",
"<em>Smack!</em> I dodge clear of a swipe, and a red takes it instead. Hilarious!",
"<em>Boom!</em> That got him",
"Two reds recharging down the side (covie cover rock is at top left)",

"Ever have one of those days?",
"Here's a little present for ya!",
"Triggers down men, here they come!",
"<em>Oooh&hellip;</em> pretty!",
"That's it boys, keep me safe",
"Leaving so soon Johnson?",
"Yeah ok Stacker, calm down - they're not even here yet",
"Stacker and Johnson let rip from a deep crossfire position",
"<em>Three reds?</em> Oh give me a break!",
"Not so fast, squid-face!",

"Here come the Jackals&hellip;",
"Ah, that's what we like to see",
"Breaking up the attack from behind",
"Heading into the hidey-hole",
"Top of the alley",
"Hey, that's enough of that pointing!",
"That's one very frustrated mob",
"That beaky fool hasn't spotted us yet",
"Stacker you idiot! Have you never heard of a chain reaction?",
"Peeling off up the edge",

"Now that's teamwork!",
"And now for your beaky buddies",
"Jackal posse ahoy!",
"Watch out for that Grunt fellas",
"Hey, can I play too?",
"Pesky grunty infiltrator!",
"Aerial attack from behind",
"Look what I've got for you grunty!",
"Hold firm Johnson!",
"Now add a plasma grenade",

"Let 'em have it sarge!",
"Ok guys, we're there",
"Fragged 'em!",
"Say goodbye, blue-boy",
"He's going to regret that swipe",
"Not so fast with that plasma grunty",
"Take 'em down boys!",
"Look left Johnson",
"I've got that Jackal covered guys",
"Double hurt",

"Triple Jackal frag",
"There seems to be something stuck to you Mr Jackal",
"Eeek!",
"Threading past the lifeboat",
"Cyborgs to the rear!",
"Could be a tricky situation",
"If in doubt, add grenades",
"Arrgh! Should've kept a closer eye on my motion tracker",
"He is <em>not</em> happy about this"),

new Array( // Flood onslaught challenge
"Run grunty, run!",
"Grunts in trouble",
"Shut up with that racket over there!",
"And now grit your teeth&hellip;",
"Oh dear. Maybe I should've jumped after all&hellip;",
"Most satisfactory",
"Arrgh! Don't bring that thing back here!",
"Plasma out!",
"It's gonna blow!",
"Get <em>back</em> you nibbling pests!",

"Don't come gurgling at <em>me</em> fella!",
"Shotty to the rescue!",
"Oh yuk, I hope no one's expecting me to clean up after this",
"Hey tubby, it'd be nice if you could hunker down and pop now",
"Jumping over closing enemies while reloading",
"Have some of this plasma fellas",
"Don't even <em>think</em> about slapping me!",
"I'm over here you gurgling idiot!",
"My shotty will sort this guy out"),

new Array( // Spiral path megabattle
"Too late, squid-face!",
"About to fire between the Ghosts",
"Toasted Wraith - medium rare",
"That's it folks, step this way",
"Grunty gunner goes for a ride",
"Pass guards triggered",
"Swooping into the pass",
"Get a move on you stragglers!",
"You're outta here squid-face!",
"That's a lotta covies down there",

"Never even knew what hit 'em",
"Cyborg ready for action!",
"Yep, I'm right in front of you",
"Balcony Elite leaping off",
"C'mon everyone, follow me!",
"Quite a crowd down there",
"One nasty accident coming right up",
"Final phase coming up&hellip;",
"Freefalling to glory",
"Checkpoint granted",

"Heads down boys, here I come!",
"Right behind you!",
"Purple snow - my favourite",
"Beaky targets ahoy!",
"Not so fast Mr Elite!",
"Heh-hey, that got 'em!",
"That sniper doesn't waste much time",
"<em>That'll</em> teach him to drop in uninvited!",
"So many targets&hellip;",
"Score 3 for the cyborg!",

"Here's a pressie for ya!",
"Bye-bye covies!",
"Ok boys, here they come!",
"I'll soon sort this guy out",
"Tagged him! Watch and enjoy&hellip;",
"That's it buddy, let him have it!",
"On the whole, I'd say this has gone a bit pear-shaped",
"I'm just glad <em>I'm</em> not down there!",
"- Before -",
"- After -",

"Hey, it's rude to point!",
"Synchronized panicking",
"Things are hotting up around here",
"<em>Retreat</em>, you bozos!",
"Up on the pillar platform",
"I sense some mischief coming on",
"Yep, should be safe enough up here!",
"Keep going men, I'm right behind you!",
"Out of my way squid-face!",
"Uh-oh, Hunter!",

"Whoa, there's a mess of 'em!",
"Onwards to victory!",
"Got 'em on the run now boys!",
"That's it buddy, let 'em have it",
"<em>KER-BLAM!</em>",
"3-Ghost pass blockade",
"Doggone long-range Hunter fire!",
"Here they come&hellip;",
"Nice shooting Marine!",
"And that's just for starters!",

"I'll soon fix these guys",
"<em>This</em> should do the job"),

new Array( // Descent trick
"About to bounce off the ledge",
"I hope those branches are soft!",
"Checkpoint done - ready to go!",
"I spy&hellip; the best rock!",
"There's no going back now"),

new Array( // Dustbowl megabattle
"Uh-oh, grunty opposition!",
"Exodus to the dustbowl",
"Accidents will happen&hellip;",
"Small dark rock on the right",
"&hellip;and back we go again",
"Stop shooting me!",
"Almost at the trigger point",
"Those Grunts are hopping mad",
"We'll soon get these shifted",
"Darn, I've got a few stragglers",

"Ok, brace yourself&hellip;",
"Ready for action!",
"Woof woof!",
"This doesn't look good",
"So much for plan A",
"You're outta there grunty!",
"Just one more whack&hellip;",
"<em>Ping!</em> Roll please Mr Jackal",
"Yeah you <em>better</em> panic!",
"Say goodbye squid-face",

"Dang, these critters aren't shifting",
"Mind if I use your cave?",
"Hah, tagged him!",
"Oh my stars and garters!",
"So many possibilities&hellip;",
"Who says Jackals can't fly?",
"That's right grunty, you're next",
"That's a lot of grunty trouble",
"Ever feel a bit cornered?",
"Clear!",

"Now this is what I call fun!",
"I think you're supposed to <em>throw</em> them, not stick them on your nose",
"Carnage at the ramp entrance",
"Arrgh! Get back you grunty devils!",
"Good deeds were done here",
"Hold it right there fellas",
"That's a lot of red dots down below!",
"Higher next time please",
"Bye bye grunty",
"Time for a bit of mopping up",

"Catch me if you can",
"I hear a lot of mumbling up there",
"Rough indication of part of the strip",
"Checkpoint&hellip; done",
"Outta my face you grunty fool!",
"Grunty assailant at 12 o'clock!",
"Save this checkpoint for safety"),

new Array( // An extra warthog
"Backed up down the corridor",
"Hey guys, look what I've got for you!"),

new Array( // Three extra Marines and a hog
"Wait there men, I'll be back later",
"Diagonal position, before dismounts",
"Charge!",
"First bozo blocked by the hog",
"That's some mighty handy shooting there soldier!"),

new Array( // Seven extra Marines and a hog
"Rattle that chain-gun!",
"Geez, wake up won't you Stacker?",
"Back with my new toy!",
"Lift comes down, Marines outside get removed",
"At the door, ready for action!",
"Just before the loading point",
"<em>That</em> got his attention",
"Here they come&hellip;",
"And here's a frag for good measure!",
"Hit that pedal!",

"No I do <em>not</em> have time to sign an autograph!",
"Good shooting from up here eh lads?",
"One Wraith nicely toasted",
"Hey guys, where've you been?",
"That's a lot of bozos",
"Just one Elite left men!",
"Link-up area indicated",
"That's it buddy, hop on down",
"Oooh, that looks messy",
"Never knew what hit 'em",

"Fizzing gift for the new arrivals",
"Flying Ghost!",
"This'll come in handy"),

new Array( // Marine-retaining Warthog
"Keep up the good work buddy!"),

new Array( // Marineless first snow battle
"<em>Blam!</em> No more Ghost",
"First of many missed swipes"),

new Array( // Danger! Falling Grunts
"There's grunty trouble on that hill",
"It's raining Grunts!",
"Here's a little smackeroo for ya",
"Right behind you!",
"Spot the falling Grunt",
"We have lift-off!",
"Down in front!",
"You messed <em>that</em> one up eh grunty?",
"See the world with Needler Airlines",
"<em>Ka-boom!</em>",

"Grunty attack from the sea!",
"Handy spares in front",
"Grunty action coming right up!",
"Checkpoint trigger line",
"Ok, who's up for a tail-slide?"),

new Array( // Boarding challenge
"He's not too happy about that",
"Have some of this fellas"),

new Array( // Twin bridges megabattle
"To be honest chum,that sword's a bit of a giveaway",
"Low over the zigzag path",
"Yay! Another two party guests",
"So many lovely choices&hellip;",
"Checkpoint&hellip; done",
"Get a move on won't you?",
"That's it grunty, clear off",
"Ok spiky, follow me!",
"Out of that Shade!",
"Close-range surprise",

"High bombardment",
"Time for some fast sniping",
"Triggers down men!",
"Say hello to the cyborg fellas",
"Aw nuts, there goes my blockade",
"Here they come",
"Oooh, nasty",
"Surprise!",
"Not so fast over there Mr Jackal",
"Right behind you!",

"That's right, it's a plasma grenade",
"That snow's looking a bit red",
"Platform swarm ahoy!",
"Good teamwork men",
"Wait up you crazy fools!",
"Looks like another busy day",
"Time for a rocket I think",
"Rocket fun from above",
"Distant grunty targets",
"Just don't fall off!",

"Time for some mischief",
"Have some green plasma fellas",
"Gangway!",
"I've got one of those too grunty!",
"Time to switch weapons I'd say",
"Don't stop now men",
"Ok covies, prepare to die",
"Nice collection ready, so let's go!",
"Drawing enemies out of the pass",
"Uh-oh, he's come back to get me",

"Let's try a few here",
"And that takes care of <em>him!</em>",
"About to throw a needler off",
"Spares placed in the battlefield, including a few place-holders",
"Rooftop goodies!",
"I'll have this needler up there in no&nbsp;time",
"Pursuers led far from the tunnel",
"Transferring to a Ghost safely",
"Sorry chum but I want that hardware",
"Lining up my first shot",

"A standard enemy layout",
"Step this way folks",
"Let the carnage begin!",
"Sorry fella, no Hunters today",
"Ok Johnson, let's try you over here",
"Time to leave I think!",
"Watch out fellas - incoming!",
"Happy landings grunty",
"Up on the Banshee canopy",
"Hold back those Elites men!",

"How's it going down there chaps?"),

new Array( // Tackling the two-door attack
"&quot;Wait here in this death trap while I go have a sandwich. Ha ha ha ha.&quot;",
"Triple kill coming right up",
"Little pressie for ya",
"Get back you gurgling freaks!",
"Hah, that got 'em"),

new Array( // Level 1 talk-through
"Spot the space-bats",
"&quot;&hellip;and a pool of their own blood to drown in!&quot;",
"Give me a sign dammit!",
"Good idea buddy!",
"Oh stuff a sock in it squid-face",
"Point that somewhere else mister",
"&quot;I'm initiating protocol Baccy-1. The pipe must be saved at all costs&quot;",
"&quot;Careful with this son, I keep my spare tobacco in the clip&quot;",
"You're next grunty",
"Hold on boys, I'm coming!",

"Get those teeth outta my face!",
"Johnson dead already! But don't worry, he'll get better",
"He's dead and you're <em>still</em> missing?",
"Dammit Johnson, that's twice you've been killed already!",
"Uh-oh, a grunty lookout!",
"More pests around the corner",
"Hurry up and die then you idiots",
"Cyborg to the rescue!",
"That was nearly you mate",
"One tagged Elite coming right up",

"Bloody hell Sarge, not <em>again?</em>",
"Time for some plasma drilling",
"Courageous grunty troopers in action",
"Better whack him quick before that Grunt raises the alarm",
"Things aren't looking too good for you now grunty",
"Hey red, here's a plasma for ya!",
"Caution: Low-flying Grunts",
"Huh? Who dat?",
"Hold on tight!"),

new Array( // Elite fireworks
"Ghosts impeded",
"Cyborg incoming!",
"<em>Blam!</em> Over you go boys",
"I'll take that needler grunty",
"Weird frozen pilots",
"Almost finished now",
"Release line indicated",
"Rotation via Banshee leg",
"Pre-frozen victims!",
"Sweep that Ghost away",

"Now you see him&hellip;",
"&hellip;now you don't!",
"Skipping the two-Wraith area",
"Less stuff, higher clip tolerance?",
"Checkpoint for maximizing yield",
"This lot should do nicely",
"Could come in handy",
"Close and personal",
"Definitely dead now",
"Sending him off at a low angle",

"Oooh, that's gonna sting",
"Houston, we have lift-off!",
"Enemies triggered without crossing the release line",
"A few more rockets should do",
"And they're pretty too!",
"This guy's going vertical",
"Hey, who turned off the snow?",
"Speedy dust puffs",
"Step right this way fellas",
"X is for Xbox",

"Isn't that a lovely sight?",
"Pre-frozen and flickering!",
"That's another Jackal down",
"This won't hurt a bit",
"<em>BLAM!</em>",
"There they go!",
"Launching with a nice pink bang",
"Fancy seeing <em>you</em> up here!",
"Extreme launch speed making individual explosions clear",
"Don't know why that red's looking so casual - he's next!",

"Watch him go!",
"And don't come back!",
"Fizzy friends",
"Hey, I'm just keeping his feet warm",
"It's nothing personal fella",
"Ok, so maybe I lied",
"See the cute little cartoon kitty?",
"That's not gonna be easy to clean off",
"So long fellas!",
"I'd say that was another hit",

"A red makes a close geological inspection of the cliff face",
"1: Near the loading point",
"2: Corner past the loading point",
"3: Covie corner",
"4: Near the tunnel exit",
"5: View back down the tunnel",
"6: Tower front door",
"7: Tower interior",
"8: Tower ramp",
"9: Tower back door",

"11: Pass and spiral path",
"12: Underpass entrance",
"13: Over the underpass",
"14: Start of the twin bridges area",
"15: Back of the twin bridges area",
"16: Trough passage entrance",
"17: Opposite passage entrance",
"18: Exit door",
"Leaving so soon?",
"Frozen crouch"),

new Array( // Banshee battles
"Fast sniping required, before the covies are into the rocks",
"C'mon fella, get a move on!",
"Gangway! Third pair coming through",
"Base camp bozos get spooked by a departing dropship",
"Let battle commence!",
"Everyone ok?",
"Duck sarge!",
"Good shooting men",
"Dang, there go Stacker and Johnson",
"Making a small circle, causing the pursuer to overshoot",

"I question the value of that frag at this time, Mr Bozo",
"Real good work boys",
"Watch it guys, here comes another",
"Got something on your tail fella",
"Stacker and Johnson let rip",
"Easy target over the stream",
"C'mon guys, what are you waiting for with those triggers?",
"Watch out fella, this pilot's crazy!",
"Trouble in the cliffside survivor area",
"Heads down men!",

"Wait here guys, I'm off for the sniper",
"Hop aboard Stacker",
"Uh-oh - squash attack!",
"Bet you thought I'd forgotten you",
"Woo-hoo! Big mound, big air",
"Say hello to the Bozo brothers",
"He seems pleased to see us",
"Close encounter heading up over the big mound",
"One down, one to go",
"Checkpoint trigger line indicated",

"They must be dizzy as hell by now",
"Waiting, clear of the passage"),

new Array( // Evac prevention at the first structure
"Frag out!",
"Red stunned 'n tagged while the blue misses a swipe, hee hee!",
"Whoops, there goes your ride boys",
"&quot;Alright ladies, volunteers step up on the double, the rest of you get to the dropship&quot;",
"Hold on tight Sarge"),

new Array( // Right behind you
"Move it from here&hellip;",
"&hellip;to here",
"Outta that seat grunty!",
"Here he comes!",
"Right behind you!",
"Missed&hellip; missed&hellip; missed&hellip;",
"&quot;What the? Grenade!&quot;",
"That is one serious case of the heebie-jeebies",
"Destination: windy tunnel",
"Something fishy going on here&hellip;",

"Dive grunty, dive!",
"Skipping the two-Wraith area",
"One ejected Grunt coming right up",
"Come on grunty, get out of there - I&nbsp;haven't got all day",
"<em>Whatever</em> his name is, this critter means business!",
"No good putting your hands up grunty - I don't take prisoners",
"He's gonna get such a shock&hellip;",
"Look at him go!"),

new Array( // Shortcut fun
"Head for the rocks at the end",
"Hey beak-brains, it's not the <em>Flood</em> you should be worried about",
"Welcome to the swamp fellas",
"I'm going to enjoy this",
"The heebie-jeebies seem very popular around these parts",
"Clambering up the slope",
"Useful rocky cover against stiff beaky resistance",
"Have some of these needles grunty",
"Gimme some boost!",
"Three tags, woo-hoo!"),

new Array( // Hidden camouflage
"Look to the left of the piping",
"Oooh, pretty!",
"Mischief outside the structure"),

new Array( // Bridge descent guide
"Entry passage checkpoint trigger line",
"Bridge checkpoint trigger line",
"This testing is gonna hurt",
"Heading off the lower deck",
"The 'V', with flattish top section",
"Thar she goes!",
"Ok, back to the drawing board",
"Ready for the run-off",
"Heading down to the ledge",
"A checkpoint helps, as usual",

"Now for the tricky bit",
"A split second before impact",
"Heading for the chevron feature on the ledge",
"Chevron clarified",
"&hellip;then off towards the rock",
"Going for the <em>further</em> rock",
"Hit the chevron near the middle",
"Drift towards the cliff base for a cushioned landing",
"Heading down to the ledge",
"Out to the tree and rock",

"Perfect landing off the best rock",
"Checkpoint&hellip; done. Ready to go!",
"That hog seems like an awfully small target from here",
"Woo-hoo! Didn't even dent it",
"Ready to go / Time to die",
"This could very well end badly",
"See? I told you",
"On the bridge rim, ready to throw",
"A well-timed grenade blast stops the Shade going off the ledge",
"Moving the Shade closer with a double throw from the&nbsp;V",

"About to bounce off the chevron onto the Shade",
"Phew! Finally on the ledge",
"Be with you shortly Sarge!",
"Ready to get him onto the ledge",
"Missed me, doofus",
"Heading for the chevron apex",
"Plasma ball stun. Now to give him a good whacking&hellip;",
"Happy landings fella!",
"Time to run I'd say",
"I don't want to alarm you Stacker, but you might want to look behind you",

"Plasma ball to keep him still",
"This is where we part company",
"Ok spiky, follow me!",
"We hope you enjoy your flight",
"And that takes care of that",
"Dropping down after the checkpoint",
"Left standing near the entrance",
"Let's get this thing moving",
"Watch out below - cyborg comin' in!",
"All aboard",

"<em>KLUNK!</em> Nasty ledge impact, but I'm still breathing",
"Hi fellas. What's cookin'?",
"A plasma hereabouts is ideal",
"Crash landing on the V",
"Please fasten your safety belt",
"Nice bounce, rear leg first",
"<em>Wheeeeeeee!</em>",
"Huh? You don't expect me to <em>board</em> that thing do you?",
"Nice clip with just a leg",
"Ok I'm down - now gimme something to shoot!",

"&hellip;plus a touch on the ledge",
"Thanks for the plasmas grunty!",
"We'll soon have this shifted with a few smackeroos",
"I may have got that slightly wrong",
"Way too short, way too late",
"Still no luck, but I'm getting closer!",
"What could possibly go wrong?",
"Quicker way down",
"I'll be right down fellas!",
"Hey Johnson, didn't I see you get killed on the Autumn?",

"Let the exploration begin!",
"A <em>parachute</em> would've been handy",
"Hey buddy, seen any aliens around here?",
"Handy toy for the first ground battle",
"Think I'll get off early today - I was starting to feel queasy",
"All aboard for the Juggertrout express",
"Here's my stop"),

new Array( // Massed Hunters
"It's a bit dark in here isn't it?",
"That's it fella, keep on comin'",
"Hey spiky, right behind you!",
"Argy-bargy up the ramp",
"Hunter number four added",
"Swipe dodged, and that makes six",
"Come on you two, shift!",
"Ready for battle - with handy spares",
"I'm fairly sure I lost that round",
"Come on guys, sort yourselves out",

"Yeah, you big blue jokers <em>better</em> move",
"Nice shooting, whoever that was",
"Rockety justice, firmly delivered",
"Making Marines dive as I drive the rear hog into position",
"Frag throw to shift them further",
"Squad of nine, ready for action",
"Six bozos ready for release",
"Bring him down men!",
"Up on a rock slab (platform Hunters off to the right, past the rocks)"),

new Array( // Grunt fireworks
"Ok, let's get this thing airborne",
"Hold tight grunty",
"One ejected critter coming right up",
"Into position you grunty fool!",
"Frozen trio ready for launch",
"Frozen trio of cavern Grunts",
"My first ever Grunt frozen at the Wraith ice patch",
"There's your ride little fella",
"Plateau Shade part way down",
"Twin bridges Banshee ahoy!",

"A cavern Shade moved to just before the loading point",
"<em>&quot;Waaaaah!&quot;</em> &hellip;times three",
"Almost there Mr Grunt",
"Over you go",
"Pre-frozen and ready to go",
"They call him The Pink Flash"),

new Array( // Grenade crazy Grunts
"Peppering to get him started",
"He just <em>loves</em> those plasmas",
"Bouncing off the glass walkway",
"Three on the go",
"Ready for some fun",
"Explosive elimination",
"Hey grunty, what's cookin'?",
"Getting a bit shooty"),

new Array( // Crazy-firing Grunts
"I'm over here grunty!",
"That's some serious needling",
"Crazy-firing on ice",
"What the heck are you shooting at you grunty fool?",
"Shade moved into place",
"Crossing the loading point",
"That thing's gonna burn out if you're not careful",
"Almost there now",
"Double crazy",
"Something wrong with your aim?",

"Quick spot of house cleaning",
"Passive after a failed attempt",
"Now starring in BCM45",
"Plasma blocked, delay ends")
);


// Array of path bases (the main part of the path)
var pathBases = new Array (
'Halo/Fun/Level2/RM/',
'Halo/Fun/Level9/FloodOnslaughtChallenge',
'Halo/Fun/Level5/SPM/',
'Halo/Fun/Level5/DescentTrick',
'Halo/Fun/Level3/DM/',
'Halo/Fun/Level5/ExtraWarthog',
'Halo/Fun/Level5/ThreeExtraMarines',
'Halo/Fun/Level5/SevenExtraMarines',
'Halo/Fun/Level5/MarineRetainingWarthog',
'Halo/Fun/Level5/MarinelessBattle',
'Halo/Fun/Level4/FallingGrunts',
'Halo/Fun/Level3/BoardingChallenge',
'Halo/Fun/Level5/TBM/',
'Halo/Fun/Level7/TwoDoorAttack',
'Halo/TalkThroughs/Level1',
'Halo/Fun/Level5/EliteFireworks/',
'Halo/Fun/Level2/BansheeBattles',
'Halo/Fun/Level2/EvacPrevention',
'Halo/Fun/Level5/RightBehindYou',
'Halo/Fun/Level6/ShortcutFun',
'Halo/Fun/Level6/HiddenCamouflage',
'Halo/Fun/Level5/BridgeDescentGuide/',
'Halo/Fun/Level4/MassedHunters',
'Halo/Fun/Level5/GruntFireworks',
'Halo/Fun/Level5/GrenadeCrazyGrunts',
'Halo/Fun/Level5/CrazyFiringGrunts'
);


// Gives path stem for specified set number and pic number
function GetPathStem(s, n) {

	var stem = pathBases[s - 1];
	if (stem.charAt(stem.length - 1) == '/') { // Need to deal with multi-page section

		var x = ''; // Extra to append
		switch (s) {

			case 1: { // Rockslide megabattle
				if (n == 43) x = 'Index.html';
				else if ((n >= 1 && n <=6) || (n >= 9 && n <= 12)) x = 'SettingUp';
				else if (n == 7 || n == 8 || (n >= 13 && n <= 26) || n == 79) x = 'MoreSetUpTips';
				else if ((n >= 27 && n <= 42) || n == 78) x = 'ExtraMarines';
				else if (n >= 44 && n <= 54) x = 'HordeSetUps';
				else if (n >= 55 && n <= 63) x = 'GeneralBattleAdvice';
				else if ((n >= 64 && n <= 77) || n == 164) x = 'Routes';
				else if (n >= 109 && n <= 133) x = 'BattlePlans/PlateauFrontDefence';
				else if (n >= 134 && n <= 150) x = 'BattlePlans/PlateauAlleyDefence';
				else if (n >= 165 && n <= 169) x = 'BattlePlans/PlateauBaseDefence';
				else if (n >= 80 && n <= 108) x = 'BattlePlans/FarAreaDefence';
				else if (n >= 151 && n <= 163) x = 'BattlePlans/TopPassDefence';
				}
				break;

			case 3: { // Spiral path megabattle
				if (n == 52) x = 'Index';
				else if ((n >= 1 && n <=16) || n == 18 || n == 22) x = 'SettingUp';
				else if (n == 17 || n == 19 || n == 20) x = 'MoreSetUpTips';
				else if (n == 21 || (n >= 23 && n <= 32)) x = 'BattlePlans/PathBaseDefence';
				else if (n >= 33 && n <= 40) x = 'BattlePlans/IcePathDefence';
				else if (n >= 41 && n <= 42) x = 'BattlePlans/UnderpassDefence';
				else if (n >= 53 && n <= 55) x = 'BattlePlans/PathTopDefence';
				else if (n >= 48 && n <= 49) x = 'BattlePlans/CyborgAdvance';
				else if (n >= 56 && n <= 59) x = 'BattlePlans/PassBlockadeRumble';
				else if (n >= 43 && n <= 47) x = 'BattlePlans/HighPositionDefence';
				else if (n >= 50 && n <= 51) x = 'BattlePlans/BansheeDefence';
				else if (n == 60) x = 'BattlePlans/CloakedInfiltration';
				else if (n >= 61 && n <= 62) x = 'BattlePlans/PassAttack';
				}
				break;

			case 5: { // Dustbowl megabattle
				if (n == 24) x = 'Index.html';
				else if ((n >= 1 && n <= 21) || n == 28 || n == 45) x = 'SettingUp';
				else if (n == 22 || n == 44 || n == 46 || n == 47) x = 'MoreSetUpTips';
				else if (n == 37 || (n >= 39 && n <= 43)) x = 'GeneralBattleAdvice';
				else if (n == 23 || (n >= 25 && n <= 27) || (n >= 29 && n <= 36) || n == 38) x = 'BattlePlans';
				}
				break;

			case 13: { // Twin bridges megabattle
				if ((n >= 1 && n <= 11) || (n >= 38 && n <= 42) || n == 58) x = 'BasicPlan';
				else if (n >= 43 && n <= 57) x = 'MoreSetUpTips';
				else if ((n >= 12 && n <= 15) || (n >= 59 && n <= 61)) x = 'BattlePlans/LeftSideDefence';
				else if (n == 22) x = 'BattlePlans/RightSideDefence';
				else if (n >= 23 && n <= 24) x = 'BattlePlans/BackDefence';
				else if (n >= 25 && n <= 28) x = 'BattlePlans/TroughDefence';
				else if (n >= 16 && n <= 21) x = 'BattlePlans/PlatformAmbush';
				else if (n == 36) x = 'BattlePlans/CyborgAdvance';
				else if (n >= 29 && n <= 31) x = 'BattlePlans/HighPositionDefence';
				else if (n == 32) x = 'BattlePlans/BansheeDefence';
				else if (n == 33) x = 'BattlePlans/WarthogJoyride';
				else if (n >= 34 && n <= 35) x = 'BattlePlans/DoorDefence';
				else if (n == 37) x = 'BattlePlans/UnderpassRoofMischief';
				}
				break;

			case 16: { // Elite fireworks
				if (n == 5 || n == 41) x = 'Index';
				else if ((n >= 1 && n <= 10 && n != 5) || n == 32) x = 'SettingUp';
				else if ((n >= 11 && n <= 18) || n == 29 || n == 31 || (n >= 33 && n <= 34)) x = 'FurtherSetUpAdvice';
				else if ((n >= 19 && n <= 22) || n == 30 || n== 35 || n == 37 || n == 39 || n == 40 || (n >= 42 && n <= 44) || n == 49) x = 'HavingYourFun1';
				else if ((n >= 23 && n <= 28) || n == 36 || n == 38 || (n >= 45 && n <=51 && n != 49)) x = 'HavingYourFun2';
				else if (n >= 52 && n <= 70) x = 'OtherLocations';
				}
				break;

			case 22: { // Descent guide
				if (n == 72) x = 'Index';
				else if (n >= 73 && n <= 74) x = 'WhyDescend';
				else if (n >= 1 && n <= 5) x = 'ThingsToKnow';
				else if (n >= 67 && n <= 71) x = 'DownFromNearLedge';
				else if (n >= 8 && n <= 9) x = 'NearLeftLedge';
				else if (n >= 10 && n <= 12) x = 'NearRightLedge';
				else if (n >= 13 && n <= 16) x = 'NearRightLedgeThenRock';
				else if (n >= 17 && n <= 18) x = 'NearRightLedgeThenCliffBase';
				else if (n >= 19 && n <= 21) x = 'TreeAndRock';
				else if (n >= 22 && n <= 24) x = 'FarRightLedgeThenHog';
				else if (n >= 25 && n <= 27) x = 'FarRightLedgeThenRock';
				else if (n >= 28 && n <= 32) x = 'StoppedByShade';
				else if (n >= 33 && n <= 37) x = 'StoppedByPatrollingElite';
				else if (n >= 38 && n <= 42) x = 'StoppedByGoldElite';
				else if (n >= 43 && n <= 47) x = 'StoppedByHunter';
				else if ((n >= 48 && n <= 52) || n == 75) x = 'ShadeRidingFromBridge';
				else if ((n >= 53 && n <= 57) || (n >= 76 && n <= 77)) x = 'ShadeRidingFromV';
				else if (n >= 58 && n <= 61) x = 'ShadeRidingClippingV';
				else if (n >= 62 && n <= 66) x = 'PelicanRidingViaShadeLaunch';
				else if (n >= 6 && n <= 7) x = 'SlowedByGrenade';
				}
				break;
			}

		stem += x;
		}

	return stem;
	}


function RandomInt(min, max) {

	var n = min;
	if (min < max) {
		n = Math.floor(min + Math.random() * (max + 1 - min));
		}
	return n;
	}


function DifferentRandomInt(min, max, numberToAvoid) {

	var n = min;
	if (min < max) {

		var adjustedMax = max;
		if (numberToAvoid >= min && numberToAvoid <= max) {
			--adjustedMax;
			}

		n = RandomInt(min, adjustedMax);
		if (n == numberToAvoid) {
			n = max;
			}
		}

	return n;
	}


function WeightedRandomInt(weights, weightSum) {

	var numWeights = weights.length;
	var x = Math.random() * weightSum;

	var i = 0;
	var subSum = weights[0];
	while (x >= subSum && i + 1 < numWeights) {
		++i;
		subSum += weights[i];
		}

	return i;
	}


// Globals
var numPlaces = 3;
var setNums = [0, 0, 0];
var picNums = [0, 0, 0];
var numPics = 0;
var setSizes = [];


// This updates values in setNums and picNums, trying to use mutually distinct sets
// and trying to avoid repeating any current pics.
function UpdateTeaserSettings() {

	var setAttemptLimit = 30;

	// Get set sizes and number of pics
	var numSets = captionSets.length;
	if (numPics == 0) { // Initialize
		for (var i = 0; i < numSets; ++i) {
			setSizes[i] = captionSets[i].length
			numPics += setSizes[i];
			}
		}

	// Record old settings
	var oldSetNums = setNums.slice(0);
	var oldPicNums = picNums.slice(0);

	// For each place, decide a new setting
	for (var place = 0; place < numPlaces; ++place) {

		var done = false;
		for (var setAttempts = 1; !done; ++setAttempts) { // Make an attempt

			var setNum = WeightedRandomInt(setSizes, numPics) + 1; // Candidate set number
			var theSetSize = setSizes[setNum - 1];

			var setNumGood = true;
			for (var i = 0; i < place && setNumGood; ++i) {
				if (setNum == setNums[i]) { // Set already used
					setNumGood = false;
					}
				}

			// Check for old pic from this set, to avoid
			var oldPicNumToAvoid = 0;
			for (var i = 0; i < numPlaces && oldPicNumToAvoid == 0; ++i) {
				if (setNum == oldSetNums[i]) {
					oldPicNumToAvoid = oldPicNums[i];
					}
				}

			if (oldPicNumToAvoid != 0 && theSetSize == 1) {
				setNumGood = false;  // Wouldn't be able to avoid old pic
				}

			if (setNumGood || setAttempts == setAttemptLimit) { // Accept the set index

				setNums[place] = setNum;

				var picNum = 1;
				if (theSetSize == 1) {
					done = true;
					}
				else {
					for (var picAttempts = 1; !done; ++picAttempts) { // Make an attempt
						picNum = DifferentRandomInt(1, theSetSize, oldPicNumToAvoid); // Candidate pic number
						done = true; // Provisional
						if (picAttempts == 1) { // Allow chance of special refusal
					
							if (setNum == 16) {
								if ((picNum >= 52 && picNum <= 68) && Math.random() > 0.3) { // Those pics are a bit dull
									done = false;
									}
								}
							}
						}
					}

				picNums[place] = picNum;
				}
			}
		}
	}


function ReviseTeaserPics() {

	UpdateTeaserSettings();

	// Get the code for the teaser pics element
	var code = '';
	for (var place = 0; place < numPlaces; ++place) {
		var setNumber = setNums[place];
		var picNumber = picNums[place];
		var pathStem = GetPathStem(setNumber, picNumber);
		code += '<div class="ps1"><div class="ps2"><div class="ps3"><div class="ps4"><div class="ps5">';
		code += '<div class="pic200" style="background-image:url(pics/' + setNumber + '/' + picNumber + 'b.jpg)">';
		code += '<a href="pics/' + setNumber + '/' + picNumber + '.jpg" rel="popup"></a></div><div class="captionBox200">';
		code += '<a href="' + pathStem + '.html#pic_' + setNumber + '-' + picNumber + '">' + captionSets[setNumber - 1][picNumber - 1] + '</a>';
		code += '</div></div></div></div></div></div>';
		}

	// Assign the code
	var teaserPicsElement = document.getElementById('teaserPics');
	teaserPicsElement.innerHTML = code;

	// Restore popup behaviour
	var popups = teaserPicsElement.getElementsByTagName('a');
	for (i = 0; i < popups.length; ++i) {
		if (popups[i].rel.indexOf('popup') != -1) {
			popups[i].onclick = DoPopup;
			}
		}	
	}
