
//-----------------------------------------------------------------------------
var pref_observe =
{
	QueryInterface: function(iid)
	{
		if (!iid.equals(Components.interfaces.nsISupports) && !iid.equals(Components.interfaces.nsIObserver))
			throw Components.results.NS_ERROR_NO_INTERFACE;

		return this;
	}
};

var cometbird_options = {
	
		getBoolPref: function(pref_name, default_value) 
		{
		   var result = default_value;
		   var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
		   var prefs = prefservice.getBranch("");
		   if (prefs.getPrefType(pref_name) == prefs.PREF_BOOL) 
		       try { result = prefs.getBoolPref(pref_name); }catch(e){}
		
		   return(result);
		},
	
		setBoolPref: function(pref_name, value) 
		{
			var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
		 	var prefs = prefservice.getBranch("");
		 	try { prefs.setBoolPref(pref_name, value); } catch(e){}
		},
		
		options_unload: function()
		{
			try
			{
				var pref_svc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);		
				var branch = pref_svc.getBranch("");
				branch.QueryInterface(Components.interfaces.nsIPrefBranch2).removeObserver("", pref_observe, false);
				
				var check = window.document.getElementById("useSmoothScrolling");
				if (check)
				{
					var enable = check.getAttribute("checked");
					var value = false;
					if (enable == "true")
							value = true;

		 			cometbird_options.setBoolPref("cometbird.smoothscroll.enabled", value); 
		 			dump("cometbird smoothscroll---------------------------"+value+"\n");
				}		
			}
			catch(ex)
			{
				// do nothing				
				dump("cometbird---------------------------option unload"+ex+"\n");
			}
		},
		
		options_onload: function()
		{
			try
			{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");	
				var pref_svc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);		
				var branch = pref_svc.getBranch("");
				branch.QueryInterface(Components.interfaces.nsIPrefBranch2).addObserver("", pref_observe, false);
				
				var check = window.document.getElementById("useSmoothScrolling");
				if (check)
				{
		   			var value = cometbird_options.getBoolPref("cometbird.smoothscroll.enabled"); 
		   			check.setAttribute("checked", value);
				}				
			}
			catch(ex)
			{
				// do nothing
				dump("cometbird---------------------------option load"+ex+"\n");
			}

			window.addEventListener("unload", cometbird_options.options_unload, false);
		}
};

window.addEventListener("load", cometbird_options.options_onload, false);
