Mission.tasks(0).extend ( {

	setup : function ( cb ) {
		Portal.loadPage ( this, 'ws-melissa/', null, cb );
	},
	start : function ( cb ) {
		setStoppableTimeout ( this, function ( ) {
			window.main_chat = new Chat ( "White Smoke Admins" );
			window.main_chat.showInvite = function ( ) {
				var link = document.createElement("link");
				link.setAttribute ( "rel", "stylesheet" );
				link.setAttribute ( "type", "text/css" );
				link.setAttribute ( "href", "/style/endoftheline/desktop/invite.css" );
				document.getElementsByTagName("head")[0].appendChild ( link );

				window.main_chat.showInvite = function ( ) { };

				var msg = $('<table><tr><td></td></tr></table>')
					.css ( { position : "fixed", top : 0, left : "50%", width : "450px", height : "100%", margin : "0 0 0 -225px" } )
					.appendTo ( "#portal_middle" )
					.find("td")
						.css ( { textAlign : "center" } )
						.append ( $('<div/>')
							.attr ( "id", "invite" )
							.html ( "<div><span></span><p>You've just received a screen sharing request from Melissa's Laptop. Would you like to view and control Melissa's Laptop screen?</p><p class=\"buttons\"><button class=\"accept\">Accept</button> <button class=\"decline\">Decline</button></p></div>" )
							.find ( "button" )
								.click ( function ( ) {
									$("td > div",msg).addClass("loading");
									$("button",msg).attr("disabled",true);
									Portal.loadPage ( null, "desktop/", function ( ) {
										var i = setInterval ( function ( ) {
											if ( !window.Browser ) return;
											clearInterval ( i );
											Browser.load ( "lolcats/", "http://127.0.0.1/lolcats/", function ( ) {
												$("#browser").removeClass("hidden");
												setTimeout ( function ( ) {
													window.main_chat.resume ( "Desktop loaded" );
													msg.remove();
												}, 1500 );
											}, { title : "LOLCats" } );
										}, 50 );
									} );
								} )
								.end()
							.hide()
						)
					.end();
				setTimeout ( function ( ) {
					$("td > div",msg).show();
				}, 1500 );
			}
			window.chatClient = window.main_chat.getClient();
			window.chatClient.hideDrawer();
			loadConversation ( '/scripts/endoftheline/conversations/task-0.js', function ( s ) {
				if ( s ) {
					window.main_chat.play ( window.scripts.TASK_0, function ( ) {
						cb();
					} );
				}
			} );
		}, 500 );
	}

} );
