/* Copyright 2009 Palm, Inc.  All rights reserved. */

ApnIntroAssistant = Class.create({
	initialize: function(params) {
		this.params = params;
		FirstUseUtil.addDashboardSmall($('target'));
	},
	
	activate: function () {
		
	},
		
	setup: function() {
		this.controller.listen(this.controller.get('apnErrorButton'), Mojo.Event.tap, this.tryAgain.bindAsEventListener(this));
		this.controller.listen(this.controller.get('setApnButton'), Mojo.Event.tap, this.setApn.bindAsEventListener(this));
				
		// Listen to ## key presses
		this.controller.listen(this.controller.sceneElement, Mojo.Event.keydown, FirstUseUtil.handleKeyPressEvent.bind(this));
		$('target').addEventListener(Mojo.Event.tap, FirstUseUtil.tapHandler.bindAsEventListener(this));
				
		this.showMessage();
	},
	
	showMessage: function () {
		if (Account.action == "create") {
			this.controller.get('account-creation-apn-error').style.display = 'block';
		}
		else if (Account.action == "login") {
			this.controller.get('login-apn-error').style.display = 'block';	
		}
	},
		
	handleCommand: function(event) {
		if (event.type == Mojo.Event.back) {
			event.preventDefault();
			event.stopPropagation();
		}	
	},
	
	tryAgain: function (event) {
		GsmUtil.processApnParams(this.params);
		this.popThisScene();
	},
	
	popThisScene: function() {
		Mojo.Controller.stageController.popScene();
	},
	
	setApn: function (event) {
		if (!this.buttonClicked) {
			this.buttonClicked = true;
			this.apnRequest = AppAssistant.gsmService.displayApnSettings();
			this.timer = setTimeout(this.popThisScene.bind(this), 4000);
		}	
	}	
	
});
