var FrameworkedFirstUseAssistant = Class.create({
	initialize: function() {
		this.gotAccounts = this.gotAccounts.bind(this);
	},
	
	setup: function() {
		AppAssistant.accountsService.getAllAccountsForService(this.controller, AccountsService.CONTACTS, false, this.gotAccounts)
	},
	
	gotAccounts: function(resp) {
		resp.list.each(function(acct) {
			acct.iconPath = Utilities.iconJSONToIconPath(acct.accountSpecificIcons);
			acct.type = acct.iconClass;
			acct.name = acct.login;
			if (acct.domain === 'eas') {
				if (acct.originalLogin) {
					acct.name = acct.originalLogin;
				}
			} else if (acct.domain === 'att') {
				if (acct.name.endsWith("@att.com")) {
					acct.name = acct.name.substr(0, acct.name.lastIndexOf("@att.com"));
				}
			}
		});
		this.model.accounts = resp.list;
		this.controller.modelChanged(this.model)
	},
	
	addAccount: function(e) {
		if (!e.item) {
			this.controller.stageController.pushScene('choosetransport', "firstuse", true);
			return;
		}
		if (e.item.domain == "eas") {
			var args = {
				appId: "com.palm.app.email",
				name: "wizard"
			};
			
			var params = {
				edit: false,
				id: undefined,
				type: "contacts",
				title: $L("Add An Account"),
				protocol: "EAS"
			};
			
			this.controller.stageController.pushScene(args, params);
		} else if (e.item.domain === "att") {
			var loginParams = {
				acctId: 0,
				acctLogin: undefined,
				acctTypeId: e.item.id,
				acctDomain: e.item.domain,
				acctName: e.item.name,
				iconClass: e.item.iconClass,
				numberOfTimesToPopScene: 1
			};
			this.controller.stageController.pushScene({
				appId: "com.palm.app.attsyncpanel",
				name: "validation"
			}, loginParams);
		} else {
			var loginParams = {
				acctId: 0,
				acctLogin: undefined,
				acctTypeId: e.item.id,
				acctDomain: e.item.domain,
				acctName: e.item.name,
				iconClass: e.item.iconClass,
				numberOfTimesToPopScene: 1
			};
			this.controller.stageController.pushScene("accountlogin", loginParams);
		}
	},
	
	done: function() {
		AppAssistant.contactsService.setFirstUseToFalse();
		this.controller.stageController.popScenesTo();
		this.controller.stageController.pushScene("list");
	}
});
