Mojo.Timing.enabled = false;

var AppAssistant = Class.create({
	
	initialize: function()
	{
		Mojo.Log.info("Wifi appassistant initialize");
	},
	
	handleLaunch: function(params)
	{
		Mojo.Log.info("Wifi appassistant handleLaunch");
		if (this._stageController) 
		{
			// Already running
			Mojo.Log.info("Wifi already running", Object.toJSON(params));
			this._stageController.launchHandler.launch(true, params);
		}
		else 
		{
			Mojo.Log.info("Wifi not running");
		}
	}
	
});

LaunchHandler = Class.create({
	someText: "this is the hello world text",
	
	initialize: function(stageController, launchParameters) {
		Mojo.Log.info("LaunchHandler initialize");
		this.stageController = stageController;
		this.launchParameters = launchParameters;
	},
	
	launch:  function(running, params) 
	{
		if (running) 
		{
			Mojo.Log.info("Wifi launch activate");
			//this.stageController.popScenesTo('networklist', params);
			this.stageController.popScene();
			this.stageController.pushScene('networklist', params);
			//this.stageController.activate();
		}
		else 
		{
			Mojo.Log.info("Wifi launch create");
			this.stageController.pushScene('networklist', params);
		}
	}
});

var StageAssistant = Class.create({
	
	initialize: function(){
		// The state watches for when it becomes active.
		Mojo.Log.info("Wifi stageassistant initialize");
	},
	
	setup: function(){
		Mojo.Log.info("Wifi stageassistant setup");
		var params = {};
	    try {
	        if (PalmSystem.launchParams) {
	            Mojo.Log.info("MojoSystem setup" + Object.toJSON(PalmSystem.launchParams));
	            params = PalmSystem.launchParams.evalJSON(true);
	        }
	    } 
	    catch (err) {
	        Mojo.Log.info("No params setup.")        
	    }

		var stageController = Mojo.Controller.stageController;
		this.launchHandler = new LaunchHandler(stageController, params);		
		
		var assistant = this.controller.getAppController().assistant;	
		assistant._stageController = this;		
		
		this.launchHandler.launch(false, params);
	},
});
	
