Mission.tasks(2).extend ( {

	setup : function ( cb ) {
		Portal.loadPage ( this, 'map/', function ( ) { cb(); } );
	},
	start : function ( cb ) {
		loadScript ( '/scripts/chat/audio.js', function ( s ) {
			loadConversation ( '/scripts/gatecrashers/conversations/end.js', function ( s ) {
				var ringing = new SoundStage.Sound( '/audio/ringtone.mp3', { id : "task3_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 the call..." );
					window.conversation = new Audio ( window.scripts.END, true, function ( ) {
						doAction ( '0b893f' );
						if ( !Portal.hintsUsed() )
							doAction ( 'cc338b' );
						cb();
					} );
				} );
			} );
		} );
	}

} );

