var transition = function ( content, ttl, cb ) {
	var $content = $(content);
	$content.appendTo ( '#portal_body');
	$content.css ( {
		position : 'absolute',
		top : '50%',
		left : '200%',
		opacity : 0
	} );
	$content.css ( {
		marginLeft : $content.outerWidth()/-2,
		marginTop : $content.outerHeight()/-2
	} );
	$content.animate ( {
		left : '50%',
		opacity : 1
	}, {
		duration : 2500,
		complete : function ( ) {
			setTimeout ( function ( ) {
				$content.animate ( {
					left : '-100%',
					opacity : 0
				}, {
					duration : 2500,
					complete : function ( ) {
						$content.remove();
						if ( typeof cb == "function" ) cb();
					}
				} )
			}, ttl || 2500 );
		}
	} );
}

Mission.tasks(4).extend ( {

	setup : function ( cb ) {
		Portal.loadPage ( this, 'blank/', null, function ( ) {
			$("#portal_overlay").empty().hide();
			$("#display").remove();
			cb();
		});
	},
	start : function ( cb ) {
		setStoppableTimeout ( this, function ( ) {
			loadConversation ( '/scripts/endoftheline/conversations/task-4.js?1', function ( s ) {
				var note = $('<div>3 months later</div>').css ( {
					color : "white",
					fontSize : "3em",
					whiteSpace : "nowrap"
				} );
				transition ( note, null, function ( ) {
					var chat = new Chat();
					chat.play ( window.scripts.TASK_4, function ( ) {
						cb();
						//alert ( "Done" );
					} );
				} );
			} );
		}, 500 );
	}

} );

