var IPOXStorage, ipoxstorage, userstorage = {};

IPOXStorage = function ($)
{
	var that = this;
	
	this.init = function ()
	{
		this.get_data();
	};
	
	this.store = function (key, value)
	{
		userstorage[key] = value;
		this.update();
	};
	
	this.retrieve = function (key) {
		if (userstorage[key]) {
			return userstorage[key];
		} else {
			return false;
		}
	};
	
	this.update = function ()
	{
		var cookie, wdata, expire = new Date(), domain, path;
		try {
			cookie = 'wdata=' + encodeURIComponent(JSON.stringify(userstorage, null, 0)) + ';';			
			expire = new Date(expire.getTime() + 1000 * 60 * 60 * 24/* * 365*/);
			expire = 'expires=' + expire.toGMTString() + ';';
			cookie += expire;
			domain = icl_home.split('/')[2];
			//cookie += 'domain=' + domain + ';path=/;'
			//path = icl_home.replace(LANG + '/', '').substr(icl_home.indexOf(domain) + String(domain).length);
			//path = path.length === 0 ? '/' : path;
			path = "/";
			cookie += 'path=' + path + ';';
			document.cookie = cookie;
			//Wlog(path);
		} catch(e) {
			Wlog('could not update the storage (' + e + ')');
		}
	};
	
	this.get_data = function ()
	{
		if (document.cookie) {
			var cookie_data, i, tmp, wdata;
			cookie_data = document.cookie.split('; ');
			for (i = 0; i < cookie_data.length; i++) {
				tmp = cookie_data[i].split('=');
				if (tmp[0] == "wdata") {
					wdata = JSON.parse(unescape(tmp[1]));
					break;
				}
			}
			for (i in wdata) {
				if (wdata.hasOwnProperty(i) && i !== '_proto_') {
					userstorage[i] = wdata[i];
				}
			}
		}
	};
	
	$(document).ready(function () {
		that.init();
	});
};
ipoxstorage = new IPOXStorage(jQuery);

