Mission.tasks(2).extend ( {

	setup : function ( cb ) {
		Portal.loadPage ( this, 'desktop/', null, function ( ) {
			$("#browser").addClass("hidden");
			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-2.js', function ( s ) {
				loadScript ( '/scripts/chat/audio.js', function ( ) {
					var ringing = new SoundStage.Sound( '/audio/ringtone.mp3', { repeat : true, noSubtitles : true, autoPlay : true, volume : 50 } );
					var timeout = setTimeout( function () {
						ringing.stop();
						$( '#hud-incoming-call' ).remove();
						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 );
						ringing.stop();
						$( '#hud-incoming-call' ).remove();
						new Audio ( window.scripts.TASK_2, true, cb );
					} );
				} );
			} );
		}, 500 );
	}

} );
