function AudioAssistant()
{
	this.commandMenuItems = new Array();
	this.commandMenuModel = {
			visible:true,
			items: [{ }] 
    };
	this.cmdmenuItemContinue = new Object();
}

AudioAssistant.prototype.Initialize = function()
{
	this.controller.get('AudioIntro').hide();
	this.controller.get('AudioChoose').show();	

	this.commandMenuItems.pop();
	this.cmdmenuItemContinue.label = $L("Start");
    this.cmdmenuItemContinue.command = "handleStart";
	this.commandMenuItems.push(this.cmdmenuItemContinue);
	
	this.commandMenuModel.items = this.commandMenuItems;
	this.controller.modelChanged(this.commandMenuModel);
	
	

}

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

AudioAssistant.prototype.setup = function()
{
	this.telephoneEvent = true;
	this.speakerphoneEvent = true;
	this.headsetJackEvent = true;
	this.headsetMicrophoneEvent = true;
	this.stereoHeadphonesEvent = false;
	this.appMenuModel = {
		visible: true,
		items: [Mojo.Menu.editItem, Mojo.Menu.helpItem]
	};
	this.controller.setupWidget(Mojo.Menu.appMenu, {omitDefaultItems: true}, this.appMenuModel);
	
	this.telephoneAttribute = {
		modelProperty:"value"
	};

	this.telephoneModel = {
		 value: this.telephoneEvent,
	};
	
	this.speakerphoneAttribute = {
		modelProperty:"value"
	};
	this.speakerphoneModel = {
		value: this.speakerphoneEvent,
	};
	this.headsetJackAttribute = {
		modelProperty:"value"
	};
	this.headsetJackModel = {
		value: this.headsetJackEvent,
	};
	this.headsetMicrophoneAttribute = {
		modelProperty:"value"
	};
	this.headsetMicrophoneModel = {
		value: this.headsetMicrophoneEvent,
	};
	this.stereoHeadphonesAttribute = {
		modelProperty:"value"
	};
	this.stereoHeadphonesModel = {
		value: this.stereoHeadphonesEvent,
	};
	this.controller.listen('telephone_div', Mojo.Event.tap, this.handleTelephone.bind(this) );
	this.controller.listen('telephone', Mojo.Event.propertyChange, this.handleTelephone.bind(this) );
	this.controller.listen('speakerphone_div', Mojo.Event.tap, this.handleSpeakerphone.bind(this) );
	this.controller.listen('speakerphone', Mojo.Event.propertyChange, this.handleSpeakerphone.bind(this) );
	this.controller.listen('headsetJack_div', Mojo.Event.tap, this.handleHeadsetJack.bind(this) );
	this.controller.listen('headsetJack', Mojo.Event.propertyChange, this.handleHeadsetJack.bind(this) );
	this.controller.listen('headsetMicrophone_div', Mojo.Event.tap, this.handleHeadsetMicrophone.bind(this) );
	this.controller.listen('headsetMicrophone', Mojo.Event.propertyChange, this.handleHeadsetMicrophone.bind(this) );
	this.controller.listen('stereoHeadphones_div', Mojo.Event.tap, this.handleStereoHeadphones.bind(this) );
	this.controller.listen('stereoHeadphones', Mojo.Event.propertyChange, this.handleStereoHeadphones.bind(this) );
		
	this.controller.setupWidget('telephone', this.telephoneAttribute, this.telephoneModel);
	this.controller.setupWidget('speakerphone', this.speakerphoneAttribute, this.speakerphoneModel);
	this.controller.setupWidget('headsetJack', this.headsetJackAttribute, this.headsetJackModel);
	this.controller.setupWidget('headsetMicrophone', this.headsetMicrophoneAttribute, this.headsetMicrophoneModel);
	this.controller.setupWidget('stereoHeadphones', this.stereoHeadphonesAttribute, this.stereoHeadphonesModel);
		
	
	var cmdmenuItem1 = new Object();
    this.commandMenuItems.push(cmdmenuItem1);
	var cmdmenuItem1 = new Object();
    this.commandMenuItems.push(cmdmenuItem1);
    this.cmdmenuItemContinue.label = $L("Start");
    this.cmdmenuItemContinue.command = "handleStart";
    this.commandMenuItems.push(this.cmdmenuItemContinue);
	
	this.commandMenuModel.items = this.commandMenuItems;

	
    this.controller.setupWidget(Mojo.Menu.commandMenu, {}, this.commandMenuModel);
	//this.controller.get('start').observe(Mojo.Event.tap, this.handleStart.bindAsEventListener(this));
	//this.controller.get('continue').observe(Mojo.Event.tap, this.handleContinue.bindAsEventListener(this));

	this.Initialize();
}

AudioAssistant.prototype.deactivate = function()
{
	this.Initialize();
}

AudioAssistant.prototype.handleTelephone = function( )
{
	if (this.telephoneEvent == true)
		this.telephoneEvent = false;
	else
		this.telephoneEvent = true;
	if (this.telephoneEvent == false) {
		this.telephoneModel.value = false;
	}
	else {
		this.telephoneModel.value = true;
	}
	this.controller.modelChanged(this.telephoneModel);
}

AudioAssistant.prototype.handleSpeakerphone = function( )
{
	if (this.speakerphoneEvent == true)
		this.speakerphoneEvent = false;
	else
		this.speakerphoneEvent = true;
	if (this.speakerphoneEvent == false) {
		this.speakerphoneModel.value = false;
	}
	else {
		this.speakerphoneModel.value = true;
	}
	this.controller.modelChanged(this.speakerphoneModel);
}

AudioAssistant.prototype.handleHeadsetJack = function( )
{
	if (this.headsetJackEvent == true)
		this.headsetJackEvent = false;
	else
		this.headsetJackEvent = true;
	if (this.headsetJackEvent == false) {
		this.headsetJackModel.value = false;
	}
	else {
		this.headsetJackModel.value = true;
	}
	this.controller.modelChanged(this.headsetJackModel);
}

AudioAssistant.prototype.handleHeadsetMicrophone = function( )
{
	if (this.headsetMicrophoneEvent == true)
		this.headsetMicrophoneEvent = false;
	else
		this.headsetMicrophoneEvent = true;
	if (this.headsetMicrophoneEvent == false) {
		this.headsetMicrophoneModel.value = false;
	}
	else {
		this.headsetMicrophoneModel.value = true;
	}
	this.controller.modelChanged(this.headsetMicrophoneModel);
}

AudioAssistant.prototype.handleStereoHeadphones = function( )
{
	if (this.stereoHeadphonesEvent == true)
		this.stereoHeadphonesEvent = false;
	else
		this.stereoHeadphonesEvent = true;
	if (this.stereoHeadphonesEvent == false) {
		this.stereoHeadphonesModel.value = false;
	}
	else {
		this.stereoHeadphonesModel.value = true;
	}
	this.controller.modelChanged(this.stereoHeadphonesModel);
}

AudioAssistant.prototype.handleStart = function()
{
	this.controller.get('AudioChoose').hide();
	this.cmdmenuItemContinue.label = $L("Continue");
    this.cmdmenuItemContinue.command = "handleContinue";
	//this.commandMenuItems.push(this.cmdmenuItemContinue);
	
	this.commandMenuModel.items = this.commandMenuItems;
	this.controller.modelChanged(this.commandMenuModel);
	this.controller.get('AudioIntro').show();

	SceneChoices.Initialize( $L("Audio Tests"), $L("The audio tests are complete.") );

	if ( this.stereoHeadphonesModel.value )
		SceneChoices.push( "audioStereoHeadphones" );
	if ( this.headsetMicrophoneModel.value )
		SceneChoices.push( "audioHeadsetMicrophone" );
	if ( this.headsetJackModel.value )
		SceneChoices.push( "audioHeadsetJack" );
	if ( this.speakerphoneModel.value )
		SceneChoices.push( "audioSpeakerphone" );
	if ( this.telephoneModel.value )
		SceneChoices.push( "audioTelephone" );
}

AudioAssistant.prototype.handleContinue = function()
{
	SceneChoices.pushNextScene(this.controller.stageController);
}

