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

Photos.Common.AutoListener = {
	autoListen: function(item, event, callback, useCapture) {
		if (!this.autoListeners) {
			this.autoListeners = [];
		}
		this.autoListeners[this.autoListeners.length] = {
			item: item,
			event: event,
			callback: callback,
			capture: useCapture
		};
		item.addEventListener(event, callback, useCapture);
	},

	removeAutoListeners: function() {
		if (!this.autoListeners) {
			return;
		}
		for (var i = 0, len = this.autoListeners.length; i < len; i++) {
			var listener = this.autoListeners[i];
			listener.item.removeEventListener(
				listener.event,
				listener.callback,
				listener.capture);
		}
		delete this.autoListeners;
	}
};

