function InteractivetestsAssistant()
{
}

InteractivetestsAssistant.prototype.testsItems =
	[{
		title: $L("Hardware buttons"),
		scene: "keyboard",
		data: $L("Test the keyboard and buttons")
	}, {
		title: $L("Touch sensors"),
		scene: "touchgrid", 
		data: $L("Test the touch screen and gesture area")
	}, {
		title: $L("Screen"),
		scene: "screen",
		data: $L("Test screen quality, proximity sensor and rotation")
	}, {
		title: $L("Audio"),
		scene: "audio",
		data: $L("Test the phone, headsets and more")
	}, {
		title: $L("Power"),
		scene: "power",
		data: $L("Test the battery and chargers")
	}, {
		title: $L("Global Positioning Services"),
		scene: "gps",
		data: $L("Test the GPS radio receiver")
    }];

/*InteractivetestsAssistant.prototype.startDisplayTest = function()
{
	this.controller.stageController.pushScene( "display" );
}*/

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

InteractivetestsAssistant.prototype.setup = function()
{
	//this.controller.window.PalmSystem.setWindowOrientation("free");

	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 cmdmenuItemSendResults = new Object();
    cmdmenuItemSendResults.label = $L("Send Results");
    cmdmenuItemSendResults.command = "handleSendResults";
    commandMenuItems.push(cmdmenuItemSendResults);
	
	this.commandMenuModel.items = commandMenuItems;

	
    this.controller.setupWidget(Mojo.Menu.commandMenu, {}, this.commandMenuModel);	*/
	
	
	
	this.testsModel = {
		items: [ ]
	};

	this.controller.setupWidget('Tests', {
		itemTemplate: 'interactivetests/item'
	}, this.testsModel);

	this.updateFields(this.testsItems, this.testsModel);

	this.controller.get('Tests').observe(Mojo.Event.tap, this.handleTap.bindAsEventListener(this));
	this.controller.get('sendResults').observe(Mojo.Event.tap, this.handleSendResults.bindAsEventListener(this));
}

InteractivetestsAssistant.prototype.cleanup = function()
{
    Mojo.log("framework-library main list scene popped.");
}

InteractivetestsAssistant.prototype.handleTap = function(event)
{
	var targetRow = this.controller.get(event.target);
	if (!targetRow.hasClassName('palm-row')) 
	{
		targetRow = $(event.target).up('div.palm-row');
	}

	if (targetRow) 
	{
		this.controller.stageController.pushScene(targetRow.id);
		event.stop();
	}
}

InteractivetestsAssistant.prototype.updateFields = function(list, model)
{
	model.items = [];
	for (var i=0;i<list.length;i++) {
		if ((list[i].data != undefined) && (list[i].data !== ""))
		{
			model.items[i] = {
				title: list[i].title,
				data: list[i].data,
				scene: list[i].scene
			};
		}
	}
	this.controller.modelChanged(model, this);
}

InteractivetestsAssistant.prototype.handleSendResults = function()
{
	var request = new Mojo.Service.Request('palm://com.palm.crotest', { 
		method: 'MoveLog', 
		parameters: {},
		onSuccess: function() {
			console.log("log moved to /var/cro/cro.log");
		},
		onFailure: function() {
			console.log("log failed to be moved to /var/cro/cro.log");
		}
	});
	this.controller.stageController.pushScene("sendsuccess", "interactivetests");
}

