var bmpPrefs = Components.classes["@mozilla.org/preferences-service;1"]
	.getService(Components.interfaces.nsIPrefService).getBranch("network.protocol-handler.app.");

bmpPrefs.setCharPref("lastfm", "@prefix@/bin/beep-media-player-2");

var uninstallObserver = {
	observe:function(subject, topic, data) {
		subject = subject.QueryInterface(Components.interfaces.nsIUpdateItem);

		if (subject.name == "BMP-LastFM" && data == "item-uninstalled") {
		//uninstall clean-up script
			var bmp2Prefs = Components.classes["@mozilla.org/preferences-service;1"]
			.getService(Components.interfaces.nsIPrefService)
			.getBranch("network.protocol-handler.warn-external.");

			bmpPrefs.clearUserPref("lastfm");

			if (bmp2Prefs.prefHasUserValue("lastfm")) {
			bmp2Prefs.clearUserPref("lastfm");
			}
		}
	},

	register:function() {
		var observerService = Components.classes["@mozilla.org/observer-service;1"]
			.getService(Components.interfaces.nsIObserverService);
		observerService.addObserver(this, "em-action-requested", false);
	},

	unregister:function() {
		var observerService = Components.classes["@mozilla.org/observer-service;1"]
			.getService(Components.interfaces.nsIObserverService);
		observerService.removeObserver(this, "em-action-requested");
	}
};

function loadReg() {
	uninstallObserver.register();
}

function unReg() {
	uninstallObserver.unregister();
}

addEventListener("load", loadReg, false);
addEventListener("unload", unReg, false);
