/*
	Small controller class used for first use scene.

Copyright 2009 Palm, Inc.  All rights reserved.

*/
var FirstUseAssistant = Class.create({
	
	initialize: function(sceneName) {
		
		this.sceneName =sceneName;
	},
	
	setup:function(){
		
		if(this.sceneName)
			getFirstUseManager().observeCalendarAccts(this.sceneName, this);
		
	},
	
	calendarAcctsUpdated:function(){
		
			this.modelUpdate();
			
	},
	
	modelUpdate:function()
	{
		this.model.accounts = getFirstUseManager().getAccountListModel();
		
		this.controller.modelChanged(this.model);
		
	},
	
	done: function(event) {
		Mojo.Log.info("***************in Done");
		// The user is done setting up for first use... 
		this.controller.stageController.popScene();	
		if(this.sceneName=='FirstLaunchScene'){
			finishedFirstUse();
			this.controller.stageController.pushScene({name: "day", transition: Mojo.Transition.crossFade, disableSceneScroller: true});
		}			
	},
	
	addAccount: function(event) {
		
		if (event.item && event.item.typeId) {
			//this is the case when there is no calendars set up
			var currAccount;
			var acctTypes = getFirstUseManager().getCalendarAcctTypes();
			for(i=0;i<acctTypes.size();i++)
			{
				if (event.item.typeId == acctTypes[i].name) {
					currAccount = acctTypes[i];
					break;
				}				
			}
			
				
			if (event.item.typeId == $L('Microsoft Exchange')) {
				//this is for eas which is a special case
				var args = {
					appId: "com.palm.app.email",
					name: "wizard"
				};
				
				var params = {
					edit: false,
					id: undefined,
					type: "calendar",
					title: $L("Add An Account"),
					protocol: "EAS"
				};
				if(!this.sceneName)
					this.controller.stageController.popScene();
				this.controller.stageController.pushScene(args, params);
			}
			else if(currAccount){
				
				//this is for all other account types
				this.controller.stageController.pushScene("accountlogin", 0 /*acctId*/, undefined /*acctLogin*/, currAccount.id, currAccount.serviceIcon, currAccount.name,"FirstLaunchScene");
			}
			
				
		}
		else {
			//this is the case when there are some calendars
			//but the user wants to add more 
			
			
			//this.controller.stageController.pushScene('firstuse', true /*showNoThanks*/);
			var acctTypes= getFirstUseManager().getAccountTypeAttribute();	
		
			var acctList=[];
		
		
			this.controller.stageController.showFirstLaunchScene({
				sceneName: 'FirstLaunchNoAcctsScene',
				title:$L('Your Calendar accounts'),
				iconPath:'icon.png',
				assistant: new FirstUseAssistant(),
				accountTypes: acctTypes
				}, {
					accounts: acctList
				});
		}
	}
	

});