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

var Settings = Class.create({
	initialize: function() {
		this.settingsCookie = new Mojo.Model.Cookie(Settings.kCookieKey);
		if (!this.settingsCookie) {
			Mojo.Log.error("Clock: Unable to access settings cookie.");
			return;
		} 
		this.load();
	},
	
	// loads settings from a cookie.  
	// if cookie is empty/invalid, uses defaults
	load: function() {
		if (this.settingsCookie) {
			this.values = this.settingsCookie.get();
			if (this.values && this.values.initialized) {
				return;
			}
		} 	
	
		this.setDefaults(); 
	},
	
	save: function() {
		if (!this.settingsCookie) {
			Mojo.Log.error("Clock: Unable to access settings cookie.");
		} else {
			this.settingsCookie.put(this.values);
		}
	},
	
	setDefaults: function() {
		this.values = {
			timePickerInterval: 5,
			dashboardHide: false,
			ringerSwitchObeyed: false,
			initialized: true
		};
		
		this.save();
		
	},
	
	timePickerIntervalGet: function() {
		return this.values.timePickerInterval;
	},
	
	timePickerIntervalSet: function(time) {
		if (!time || time < 0 || time > 30) {
			Mojo.Log.error("Clock: Time picker interval invalid; resetting to 5.");
			time = 5;
		}
		this.values.timePickerInterval = time;
		this.save();
	},
	
	dashboardHideGet: function() {
		return this.values.dashboardHide;
	},
	
	dashboardHideSet: function(state) {
		this.values.dashboardHide = state;
		this.save();
	},
	
	ringerSwitchObeyedSet: function(state) {
		this.values.ringerSwitchObeyed = state;
		this.save();
	},
	
	ringerSwitchObeyedGet: function() {
		return this.values.ringerSwitchObeyed;
	}
	
});

Settings.kCookieKey = "settings";
// TODO ALWAYS MAKE SURE THIS IS VALID
