GestureStripAssistant.prototype.Step = 0;

/************************************************************************
 * Create the class, initialize things
 ************************************************************************/
function GestureStripAssistant()
{
}

GestureStripAssistant.prototype.Initialize = function()
{
	
	var devInfo = Mojo.Environment.DeviceInfo;
	
	if (devInfo && devInfo.modelName) {
		var model_name = devInfo.modelName;
		if (model_name === "Prē") {
			this.controller.get('instructions').update( $L("Slide your finger halfway across the gesture area, as shown above.<br>Did the light on the right turn on?") );
			}
		else {
			this.controller.get('instructions').update( $L("Slide your finger halfway across the gesture area, as shown above.<br>Did the light move from left to right") );
			}
		}
	this.controller.get('image').src = "images/lightleft.png";
}

GestureStripAssistant.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();
	}
}

GestureStripAssistant.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.Initialize();
}

/************************************************************************
 * When activated, begin listening for keydown events
 ************************************************************************/
GestureStripAssistant.prototype.activate = function(param)
{
	this.Step = 0;
}

GestureStripAssistant.prototype.handleCommand = function(event)
{
	// short circuit back gesture so it doesn't do anything
	if (event.type == Mojo.Event.back)
	{
		//event.preventDefault();
		//event.stopPropogation();
		Event.stop(event);
	}else if (typeof this[event.command] == "function") {
			this[event.command](event);
		}
}


/************************************************************************
 * Upon deactivate, stop listening for the keydown event
 ************************************************************************/
GestureStripAssistant.prototype.deactivate = function()
{
	this.Initialize();
}

GestureStripAssistant.prototype.handleNo = function()
{
	var str = "No response on the " + (this.Step ? "right" : "left") + " side";
	Logging.log( "Gesture Area", str );

	this.handleSkip();
}

GestureStripAssistant.prototype.handleYes = function()
{
	var str = (this.Step ? "right" : "left") + " side successful";
	Logging.log( "Gesture Area", str );

	this.handleSkip();
}

GestureStripAssistant.prototype.handleSkip = function()
{
	if (this.Step == 0)
	{
		this.Step++;
		
		var devInfo = Mojo.Environment.DeviceInfo;
	
		if (devInfo && devInfo.modelName) {
		var model_name = devInfo.modelName;
		//We will have to keep updating these for upcoming devices
		if (model_name === "Prē") {
			this.controller.get('instructions').update( $L("Slide your finger the other way, as shown above.<br>Did the light on the left turn on?") );
		}
		else {
			this.controller.get('instructions').update( $L("Slide your finger the other way, as shown above.<br>Did the light move from right to left?") );
		}
		}
		
		this.controller.get('image').src = "images/lightright.png";
		//this.controller.get('Skip').update( $L("Done") );
	}
	else
	{
		this.controller.stageController.pushScene("complete", $L("Touch Sensor Tests"), $L("The touch sensor tests are complete.") );
	}
}


