SliderCountAssistant.prototype.HallCount = 0;
SliderCountAssistant.prototype.OpticalCount = 0;

function SliderCountAssistant()
{
}

SliderCountAssistant.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
 ************************************************************************/
SliderCountAssistant.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 cmdmenuItem1 = new Object();
    commandMenuItems.push(cmdmenuItem1);
	var cmdmenuItem2 = new Object();
    commandMenuItems.push(cmdmenuItem2);
	var cmdmenuItemContinue = new Object();
    cmdmenuItemContinue.label = $L("Continue");
    cmdmenuItemContinue.command = "handleContinue";
    commandMenuItems.push(cmdmenuItemContinue);
	this.commandMenuModel.items = commandMenuItems;

	
    this.controller.setupWidget(Mojo.Menu.commandMenu, {}, this.commandMenuModel);
	//this.controller.get('Continue').observe(Mojo.Event.tap, this.handleContinue.bindAsEventListener(this));
	//this.controller.get('Skip').observe(Mojo.Event.tap, this.handleSkip.bindAsEventListener(this));
}

SliderCountAssistant.prototype.handleContinue = function()
{
	Logging.log( "Keyboard slider", "Hall sensor: " + this.HallCount + ", Optical sensor: " + this.OpticalCount );
	this.controller.stageController.pushScene("volume");
}

/*SliderCountAssistant.prototype.handleSkip = function()
{
	Logging.log( "Keyboard slider", "Hall sensor: " + this.HallCount + ", Optical sensor: " + this.OpticalCount );
	this.controller.stageController.pushScene("volume");
}*/

SliderCountAssistant.prototype.activate = function()
{
	//console.log( "LightSensor: activate called" );
	this.getSliderCount();

}

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

SliderCountAssistant.prototype.deactivate = function()
{
	//console.log( "LightSensor: deactivate called" );
}

SliderCountAssistant.prototype.UpdateScreenSliderCount = function()
{
	//console.log( "Slider: updateScreenSliderCount()" );

	var str = $L("The Hall Sensor value is #{hallCount}. The Optical sensor value is #{opticalCount}.<br/><br/> Tap Continue to begin the next test.").interpolate({hallCount: this.HallCount,	opticalCount: this.OpticalCount});
	
	this.controller.get('instructions').update( str );
}

SliderCountAssistant.prototype.getSliderCount = function()
{
  	this.opticalCount = new Mojo.Service.Request('palm://com.palm.hidd/HidKeypad', {
					                    method: 'OpticalCount',
					                    parameters: {"mode": "get"},
										onSuccess: function(data) {
												//console.log("Slider: " + Object.toJSON(data) );

												if (data.value)
													this.OpticalCount = data.value;

												this.UpdateScreenSliderCount();
											}.bind(this),
										onFailure: function() {
												console.log("Slider: Failed to get slider count");
											}
					                	});


  	this.hallCount = new Mojo.Service.Request('palm://com.palm.hidd/HidKeypad', {
					                    method: 'HallCount',
					                    parameters: {"mode": "get"},
										onSuccess: function(data) {
												//console.log("Slider: " + Object.toJSON(data) );

												if (data.value)
													this.HallCount = data.value;

												this.UpdateScreenSliderCount();
											}.bind(this),
										onFailure: function() {
												console.log("Slider: Failed to get slider count");
											}
					                	});

	
}

