Mission.tasks(3).extend ( {

	setup : function ( cb ) {
		Portal.loadPage ( this, 'desktop/', null, function ( ) {
			if ( !window.main_chat ) {
				loadScript ( '/scripts/chat/chatclient.js', function ( ) {
					var interval = setInterval ( function ( ) {
						if ( !window.Chat ) return;
						clearInterval ( interval );

						window.main_chat = new Chat();
						window.chatClient = window.main_chat.getClient();
						window.chatClient.hideDrawer();
						loadConversation ( '/scripts/endoftheline/conversations/task-0.js', function ( s ) {
							window.main_chat.load ( window.scripts.TASK_0, function ( ) {
								loadConversation ( '/scripts/endoftheline/conversations/task-1.js', function ( s ) {
									window.main_chat.load ( window.scripts.TASK_1, cb );
								} );
							} );
						} );
					}, 100 );
				} );
			} else {
				cb();
			}
		});
	},
	start : function ( cb ) {
		setStoppableTimeout ( this, function ( ) {
			loadConversation ( '/scripts/endoftheline/conversations/task-3.js', function ( s ) {
				window.main_chat.play ( window.scripts.TASK_3, function ( ) {
					var dead = new SoundStage.Sound ( '/audio/endoftheline/m13_line_dead_2.mp3', {
						noSubtitles : true,
						length : 1.593,
						autoPlay : true
					} );
					var fadeOut = new SoundStage.Sound ( '/audio/endoftheline/m13_whitenoise.mp3', {
						noSubtitles : true,
						length : 5.616
					} );
					fadeOut.onLoad ( function ( ) {
						fadeOut.play();
						Portal.loadPage ( null, 'blank/', null, function ( ) {
							$("#portal_overlay")
								.css ( {
									opacity : 0
								} )
								.animate ( {
									opacity : 1
								}, {
									duration : fadeOut.length * 1000,
									complete : function ( ) {
										fadeOut.stop();
										window.main_chat.close();
										cb();
									}
								} );
						}, "portal_overlay" );
					} );
				} );
			} );
		}, 500 );
	}

} );

