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

AirplaneService = Class.create({
	initialize: function(){
		this.callbacks = [];
		this.serviceRequest = null;
		this.currentResponse = null;
	},
	registerForEvents: function(callback){
		this.callbacks.push(callback);
		if(this.currentResponse){
			callback(currentResponse);
		}
		if(!this.serviceRequest){
			this.serviceRequest = new Mojo.Service.Request(this.airplaneModeIdentifier, {
				method: "getPreferences",
				parameters: {
					subscribe: true,
					keys: ["airplaneMode"]
				},
				onSuccess: this.update.bind(this)
			});
		}
	},
	
	update: function(response){
		this.callbacks.each(function(cb){
			cb(response);
		});
		this.currentResponse = response;
	},
	
	airplaneModeIdentifier: "palm://com.palm.systemservice"
});
