function PowerAssistant()
{
}

PowerAssistant.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 (event.type == Mojo.Event.commandEnable && 
		 (event.command == Mojo.Menu.helpCmd)) {
		event.stopPropagation();
	}
}

PowerAssistant.prototype.setup = function()
{
	 this.acpowerEvent = false;
	this.usbcableEvent = false;
	this.touchstoneEvent = false;
	this.appMenuModel = {
		visible: true,
		items: [Mojo.Menu.editItem, Mojo.Menu.helpItem]
	};
	this.controller.setupWidget(Mojo.Menu.appMenu, {omitDefaultItems: true}, this.appMenuModel);
	
	this.ACPowerAttribute = {
		modelProperty:"value"
	};
	this.ACPowerSupplyModel = {
		value: this.acpowerEvent,
	};
	this.USBCableAttribute = {
		modelProperty:"value"
	};
	this.USBCableModel = {
		value: this.usbcableEvent,
	};
	this.TouchstoneAttribute = {
		modelProperty:"value"
	};
	this.TouchstoneModel = {
		 value: this.touchstoneEvent,
	};

	this.controller.setupWidget('ACPowerSupply', this.ACPowerAttribute, this.ACPowerSupplyModel);
	this.controller.setupWidget('USBCable', this.USBCableAttribute, this.USBCableModel);
	this.controller.setupWidget('Touchstone', this.TouchstoneAttribute, this.TouchstoneModel);
	
	this.controller.listen('acpower_div', Mojo.Event.tap, this.handleACPowerSupply.bind(this) );
	this.controller.listen('ACPowerSupply', Mojo.Event.propertyChange, this.handleACPowerSupply.bind(this) );
	this.controller.listen('usbcable_div', Mojo.Event.tap, this.handleUSBCable.bind(this) );
	this.controller.listen('USBCable', Mojo.Event.propertyChange, this.handleUSBCable.bind(this) );
	this.controller.listen('touchstone_div', Mojo.Event.tap, this.handleTouchstone.bind(this) );
	this.controller.listen('Touchstone', Mojo.Event.propertyChange, this.handleTouchstone.bind(this) );
	this.controller.get('Start').observe(Mojo.Event.tap, this.handleStartTest.bindAsEventListener(this));
}

PowerAssistant.prototype.handleStartTest = function()
{
	SceneChoices.Initialize( $L("Power Tests"), $L("The power tests are complete.") );
	if ( this.TouchstoneModel.value )
		SceneChoices.push( "Touchstone" );
	if ( this.USBCableModel.value )
		SceneChoices.push( "USBCable" );
	if ( this.ACPowerSupplyModel.value )
		SceneChoices.push( "ACPowerSupply" );

	SceneChoices.pushNextScene(this.controller.stageController);
}
PowerAssistant.prototype.handleACPowerSupply = function( )
{
	if (this.acpowerEvent == true)
		this.acpowerEvent = false;
	else
		this.acpowerEvent = true;
	if (this.acpowerEvent == false) {
		this.ACPowerSupplyModel.value = false;
	}
	else {
		this.ACPowerSupplyModel.value = true;
	}
	this.controller.modelChanged(this.ACPowerSupplyModel);
}
 
PowerAssistant.prototype.handleUSBCable = function( )
{
	if (this.usbcableEvent == true)
		this.usbcableEvent = false;
	else
		this.usbcableEvent = true;
	if (this.usbcableEvent == false) {
		this.USBCableModel.value = false;
	}
	else {
		this.USBCableModel.value = true;
	}
	this.controller.modelChanged(this.USBCableModel);
}
 
PowerAssistant.prototype.handleTouchstone = function( )
{
	if (this.touchstoneEvent == true)
		this.touchstoneEvent = false;
	else
		this.touchstoneEvent = true;
	if (this.touchstoneEvent == false) {
		this.TouchstoneModel.value = false;
	}
	else {
		this.TouchstoneModel.value = true;
	}
	this.controller.modelChanged(this.TouchstoneModel);
}


