/* $Id: UserProperties.js,v 1.7 2008-07-18 19:19:50 fwosko Exp $ */

/* Depends on:
 * - prototype.js ver. > 1.5.1
 * - jmutils.js
 */

//importScript("/js/prototype.js");
//importScript("/js/Cookies.js");

function UserProperties(){
	this.firstUserShownStamp = '2000-01-01';
	this.firstUserAnimated = false;
	this.session = {};

	this.save = function(){
		var date = new Date();
		date.setTime(date.getTime()+(10*356*24*60*60*1000));
		Cookies.setCookie("NEXTO_USER_PROPS",this.serialize(),"/",date.toGMTString());
		Cookies.setCookie("NEXTO_USER_SESSION",Object.toJSON(this.session),"/");
	}

	this.serialize = function(){
		return Object.toJSON(this);
	}

	this.restore = function(){
		var tmpCookie = Cookies.getCookie("NEXTO_USER_PROPS");
		var tmpProps = tmpCookie?UserProperties.deserialize(tmpCookie):null;
		for (var i in tmpProps) {
			var property = tmpProps[i];
			if (typeof property != 'object' && typeof property != 'function') {
				this[i] = property;
			}
    	}

		this.session = {};
		tmpCookie = Cookies.getCookie("NEXTO_USER_SESSION");
		tmpProps = tmpCookie?UserProperties.deserialize(tmpCookie):null;
		for (var i in tmpProps) {
			var property = tmpProps[i];
			if (typeof property != 'object' && typeof property != 'function') {
				this.session[i] = property;
			}
    	}
	}
};

UserProperties.deserialize = function(text){
	return text.evalJSON(true);
};

var userProps = new UserProperties();
userProps.restore();
//importScriptWait(userProps.restore);

// reference
UserProperties.userProps = userProps;

/*
Usage:
------

UserProperties.userProps.ala="beata";
UserProperties.userProps.celina="daria";
UserProperties.userProps.save();

console.debug(UserProperties.userProps);

*/