Mission.tasks(1).extend ( {

	setup : function ( cb ) {
		Portal.loadPage ( this, 'fakebook/', function ( ) { cb(); } );
	},
	start : function ( cb ) {
		var container = $('<div/>').css ( {
			//opacity : 0,
			paddingTop : 150,
			lineHeight : "2em",
			width : 200
		} ).html ( "24 hours later..." );
		var message = Portal.showMessage ( container, null, true );
		var fromSrc = function ( src ) {
			var img = new Image(150,150);
			img.src = src;
			return img;
		}
		var images = [
			fromSrc ( "/style/gatecrashers/transition/0.png" ),
			fromSrc ( "/style/gatecrashers/transition/0.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/1.png" ),
			fromSrc ( "/style/gatecrashers/transition/1.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/2.png" ),
			fromSrc ( "/style/gatecrashers/transition/2.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/3.png" ),
			fromSrc ( "/style/gatecrashers/transition/3.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/4.png" ),
			fromSrc ( "/style/gatecrashers/transition/4.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/5.png" ),
			fromSrc ( "/style/gatecrashers/transition/5.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/6.png" ),
			fromSrc ( "/style/gatecrashers/transition/6.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/7.png" ),
			fromSrc ( "/style/gatecrashers/transition/7.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/8.png" ),
			fromSrc ( "/style/gatecrashers/transition/8.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/9.png" ),
			fromSrc ( "/style/gatecrashers/transition/9.5.png" ),
			fromSrc ( "/style/gatecrashers/transition/10.png" )
		]
		var step = function ( ) {
			var image = images.shift();
			if ( image ) {
				$(container).css ( {
					background : "url(" + image.src + ") 50% 0 no-repeat"
				} );
			} else {
				finish();
				clearInterval ( interval );
			}
		}
		step();
		var interval = setInterval ( step, 100 );
		var finish = function ( ) {
			Portal.loadPage ( this, 'map/', function ( ) {
				loadScript ( '/scripts/chat/audio.js', function ( s ) {
					loadConversation ( '/scripts/gatecrashers/conversations/showdown.js', function ( s ) {
						setTimeout ( function ( ) {
							setTimeout ( function ( ) {
								SoundStage.whenReady ( function ( ) {
									Portal.setHint ( "Answer the phone" );
									var ringing = new SoundStage.Sound( '/audio/ringtone.mp3', { id : "task2_ringing", repeat : true, noSubtitles : true, autoPlay : true } );
									var stopRinging = function ( ) {
										$( '#hud-incoming-call' ).remove();
										if ( ringing.loaded() )
											ringing.stop()
										else
											ringing.onLoad ( function ( ) { this.stop(); } );
									}
									var timeout = setTimeout( function () {
										stopRinging();
										Mission.fail( 'You should have answered the phone' );
									}, 30000 );
									$( '#portal_top' ).append( '<div class="hud-box" id="hud-incoming-call"><div class="hud-box-wrapper"><div class="hud-box-inner"><div class="hud-box-content"><div class="hud-message"><button class="hud-button"><span><span>Answer phone</span></span></button></div></div></div></div></div>' );
									$( '#hud-incoming-call button' ).click( function () {
										clearTimeout( timeout );
										stopRinging();
										Portal.setHint ( "Listen to Max's instructions" );
										var gameFinished = false;
										var conversationFinished = false;
										var done = function ( ) {
											if ( gameFinished && conversationFinished ) cb();
										}
										window.beginGame = function ( ) {
											var randomTweet = ( function ( ) {
												var messages = [
													"<u>daveygardner</u> &mdash; on way to #DriffFest09 from York - traffic moving reallllyyy sllloooowwwwllly....",
													"<u>josieblue</u> &mdash; stuck in traffic - will prob be at last another 2 hours - meh. #DriffFest09",
													"<u>zac_efron_fan</u> &mdash; still moving at about 1 mile an hour, bor-ring! #DriffFest09",
													"<u>hippetyhop</u> &mdash; going so slow on this road i can count the blades of grass... #DriffFest09",
													"<u>jason_bootle</u> &mdash; hope to be there soon but traffic still a total mare. #DriffFest09",
													"<u>grace_everett</u> &mdash; lost somewhere outside driffield - help! #DriffFest09",
													"<u>amnesiagirl</u> &mdash; been driving round for ages but can't find #DriffFest09!",
													"<u>emoboy92</u> &mdash; cant see any signs for #DriffFest09! going to be late!",
													"<u>soozy_p</u> &mdash; stuck in the arse end of nowhere - no idea if we're near or not! #DriffFest09",
													"<u>vikkibarker</u> &mdash; totally Lost! be easier to find that bluddy island than this place! #DriffFest09",
													"<u>eddiesteadygo</u> &mdash; had to pull over - loasda black smoke comin from under bonnet - uh-oh! #DriffFest09",
													"<u>danny_masters17</u> &mdash; smithy forgot to fill up the oil, so we've broken down. clarkson would not be impressed... #DriffFest09",
													"<u>robbieosullivan</u> &mdash; had to pull over, something fell off car - think it was the exhaust! #DriffFest09",
													"<u>cherylkirk</u> &mdash; engine making really nasty noise - calling breakdown man now! #DriffFest09",
													"<u>annalise_gregory</u> &mdash; stuck on hard shoulder waiting for AA. beep if ya see a red astra! #DriffFest09",
													"<u>lucyfitzpatrick</u> &mdash; jenny forgot her sleeping bag so had to go back.  just leaving now! #DriffFest09",
													"<u>geri_allcott</u> &mdash; still in blacks - cant decide between blue and red tent! #DriffFest09",
													"<u>freddiecarter</u> &mdash; alison still doing her face - be there at midnight at this rate! #DriffFest09",
													"<u>barry_collinson</u> &mdash; in services - sal got carsick so having a breather. #DriffFest09",
													"<u>hilarymason</u> &mdash; have got fi and greg, only hannah to go. should be there in less than 2 hours! #DriffFest09"
												];
												var timer = null;
												var init = function ( ) {
													if ( messages.length )
														timer = setTimeout ( fireTweet, 7500 + ( Math.random() * 5000 ) );
												}
												var fireTweet = function ( ) {
													if ( Math.random() > 0.5 && messages.length ) {
														messages.sort ( function() { return 0.5 - Math.random(); } );
														GateCrashers.showTweet ( messages.pop() );
													}
												}
												init();
												return {
													reset : function ( ) {
														clearTimeout ( timer );
														init();
													}
												}
											} )();
											GateCrashers.start ( {
												oncomplete : function ( success, arrived, failed ) {
													gameFinished = true;
													if ( success === false ) {
														// failed
														Mission.fail ( "Too many people got to the pub" );
													} else {
														// passed
														doAction ( '994862' );
														/*
														if ( success > 0.75 )
															doAction ( '8d4992' );
														*/
														//if ( arrived <= 5 )
														if ( arrived <= 15 ) // Bug #4101
															doAction ( '8d4992' );
														done();
													}
												},
												onstart : function ( ) {
													window.conversation.resume ( "Started GateCrashers game" );
												},
												onbegin : ( function ( ) {
													randomTweet.reset();
													var messages = [
														"<u>jimmythered</u> &mdash; Top down, music up, life's good! #DriffFest09 here I come!",
														"<u>cindypatterson</u> &mdash; singin at the top of my voice to the killers - love festivals!!! #DriffFest09",
														"<u>david_roberts</u> &mdash; traffic moving along nicely, should be there dead on time! #DriffFest09",
														"<u>fairyprincess</u> &mdash; on way to #DriffFest09 - can't wait!!!",
														"<u>simon_ellory</u> &mdash; having a few beers in the back of the car :-) #DriffFest09",
														"<u>vix_fraser</u> &mdash; wish i'd brought my wellies now - ah well, too late - already on way! #DriffFest09",
														"<u>rob_johnson</u> &mdash; haha just saw someone pull a moonie in passing coach! #DriffFest09",
														"<u>harrykendall</u> &mdash; on the way with the gang - happy days... #DriffFest09",
														"<u>liamnesbitt</u> &mdash; still on the road but the sun's out and we're all smiling! #DriffFest09",
														"<u>rachel_wood</u> &mdash; #DriffFest09 - last festival of the year for me but hopefully the best!"
													];
													return function ( ) {
														if ( Math.random() > 0.9 && messages.length ) {
															randomTweet.reset();
															messages.sort ( function() { return 0.5 - Math.random(); } );
															GateCrashers.showTweet ( messages.pop() );
														}
													}
												} )(),
												onfail : function ( ) {
													//console.log ( "Car gave up..." );
												},
												onarrive : ( function ( ) {
													var messages = [
														"<u>lizzy_jones</u> &mdash; just arrived at #DriffFest09!  party party!",
														"<u>ellawatson</u> &mdash; @sara_forbes: don't believe wot it says on facebook - festival still on! #DriffFest09",
														"<u>sophie_lou_buxton</u> &mdash; @eviepierce, @wendysmith, @gillianackroyd: just arrived - the place is rockin!  get up here NOW!!! #DriffFest09",
														"<u>martin_burns</u> &mdash; @philmac, @bazman, @lucyreeves, @warren_phillips, @vinnie_knight: we've arrived!  where are you?  going to pitch tents - then bar! #DriffFest09",
														"<u>salrogers</u> &mdash; #DriffFest09 buzzing - when's the first band on???",
														"<u>kerrywatson</u> &mdash; @fliss_trevors: wer r u girl? so many pple here iv lost ya!!! #DriffFest09",
														"<u>becca_mason</u> &mdash; @ellagibb, @bo_chan, @kathy_king, @alanacurtis: found it really easy! get a move on ladies! #DriffFest09",
														"<u>may_wong</u> &mdash; @louie_harrison: pitchin tent now - have saved you a space - hurry!!! #DriffFest09",
														"<u>ronaldo_freak</u> &mdash; loadsa fit girls at #DriffFest09! sooo glad i came!!!",
														"<u>chelsea_stevens</u> &mdash; @rach_wilson, @georgie_bloor, @alexa_ramsden: the scarborough posse has arrived - see y'all soon I hope! #DriffFest09"
													];
													return function ( ) {
														if ( Math.random() > 0.75 && messages.length ) {
															randomTweet.reset();
															messages.sort ( function() { return 0.5 - Math.random(); } );
															GateCrashers.showTweet ( messages.pop() );
														}
													}
												} )()
											} );
										}
										window.conversation = new Audio ( window.scripts.SHOWDOWN, true, function ( ) {
											conversationFinished = true;
											done();
										} );
									} );
								} );
							}, 1000 );
							message.close();
						}, 1000 );
					} );
				} );
			} );
		}
	}

} );
