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

NosimAssistant = Class.create({
	initialize: function() {
		this.frameNum = 0;
		this.totalFrames = 5;
	},
	
	setup: function() {
		// Listen to ## key presses
		this.controller.listen(this.controller.sceneElement, Mojo.Event.keydown, FirstUseUtil.handleKeyPressEvent.bind(this));
		this.noAction = true;
		//power down after 5 mins
		this.powerDownMethod = setTimeout(this.powerDownDevice.bind(this), 1000*60*5);
	},
	
	powerDownDevice: function () {
		clearTimeout(this.powerDownMethod);
		if (this.noAction == true) {
			FirstUseUtil.powerDownDevice("User inactivity during firstuse");
		}
	},
	
	activate: function () {
		this.showNextScreen();
	},
		
	showNextScreen: function() {
		var transition = this.controller.prepareTransition(Mojo.Transition.crossFade, false);
		 
		for(var i=0; i<this.totalFrames; i++){
			if(i==this.frameNum){
				$('nosim'+(i+1)).show();				
			} else {
				$('nosim'+(i+1)).hide();				
			}
		}
		transition.run();
		
		this.frameNum = (this.frameNum + 1) % this.totalFrames;
	
		clearTimeout(this.nextMethod);
		this.nextMethod = setTimeout(this.showNextScreen.bind(this), 5000);	
	},

	handleCommand: function(event) {
		if (event.type == Mojo.Event.back) {
			event.preventDefault();
			event.stopPropagation();
		}	
	},
		
	deactivate: function() {
		this.noAction = false;
		clearTimeout(this.powerDownMethod);
	}	
});
