function KeyboardBacklightAssistant()
{
}

KeyboardBacklightAssistant.prototype.handleCommand = function(event) {
	if(event.type == Mojo.Event.command) {
		if (event.command == Mojo.Menu.helpCmd) {
			Event.stop(event);
			var openParams = {
				target: 'http://help.palm.com/device_info/index.html'
			};
			this.controller.serviceRequest('palm://com.palm.applicationManager', {
				method: 'open',
				parameters: {
					id: 'com.palm.app.help',
					params: openParams
				}
			});
		}else if (typeof this[event.command] == "function") {
			this[event.command](event);
		}
	} else if (event.type == Mojo.Event.commandEnable && 
		 (event.command == Mojo.Menu.helpCmd)) {
		event.stopPropagation();
	}
}
	
/************************************************************************
 * Do initial setup
 ************************************************************************/
KeyboardBacklightAssistant.prototype.setup = function()
{
	this.appMenuModel = {
		visible: true,
		items: [Mojo.Menu.editItem, Mojo.Menu.helpItem]
	};
	this.controller.setupWidget(Mojo.Menu.appMenu, {omitDefaultItems: true}, this.appMenuModel);
	this.commandMenuModel = {
			visible:true,
			items: [{ }] 
    }; 
	var commandMenuItems = new Array();
    
  
	var cmdmenuItemSkip = new Object();
    cmdmenuItemSkip.label = $L("Skip");
    cmdmenuItemSkip.command = "handleSkip";
    commandMenuItems.push(cmdmenuItemSkip);
	var cmdmenuItem1 = new Object();
    commandMenuItems.push(cmdmenuItem1);
	var cmdmenuItem2 = new Object();
    commandMenuItems.push(cmdmenuItem2);
	
	this.commandMenuModel.items = commandMenuItems;

	
    this.controller.setupWidget(Mojo.Menu.commandMenu, {}, this.commandMenuModel);
	//this.controller.get('Skip').observe(Mojo.Event.tap, this.handleSkip.bindAsEventListener(this));
	this.controller.get('No').observe(Mojo.Event.tap, this.handleNo.bindAsEventListener(this));
	this.controller.get('Yes').observe(Mojo.Event.tap, this.handleYes.bindAsEventListener(this));

	this.controller.get('instructions').update( $L("Take the phone to a dark place (closet or desk drawer).<br><br>Do you see the keyboard flashing on and off?") );
}

KeyboardBacklightAssistant.prototype.handleYes = function()
{
	Logging.log( "KeyboardBacklight Sensor", "Successful" );
	this.controller.stageController.pushScene("lightsensor");
}

KeyboardBacklightAssistant.prototype.handleNo = function()
{
	Logging.log( "KeyboardBacklight Sensor", "No response" );
	this.controller.stageController.pushScene("lightsensor");
}

KeyboardBacklightAssistant.prototype.handleSkip = function()
{
	this.controller.stageController.pushScene("lightsensor");
}

KeyboardBacklightAssistant.prototype.activate = function()
{
	    console.log( "KeyboardBacklightAssistant: activate called" );
        this.RequestCall = new Mojo.Service.Request('palm://com.palm.crotest', {
        	method: 'LightSensor',
            parameters: {"command": "setdata"},
            onSuccess: function() {
            console.log("LightSensor: Success blink keyboard light");
            },
            onFailure: function() {
            console.log("LightSensor: Failed blink keyboard light");
            }
        });
	console.log( "KeyboardBacklight: activate called" );
}

KeyboardBacklightAssistant.prototype.cleanup = function()
{
	//console.log( "KeyboardBacklight: cleanup called" );
}

KeyboardBacklightAssistant.prototype.deactivate = function()
{
	console.log( "KeyboardBacklight: deactivate called" );
}

