var Cookie = Class.create ({
	initialize : function (options)
	{
		this.options = { expires : 3600, path : '', domain : '', secure : '' };

		Object.extend (this.options, options || {});

		if (this.options.expires > 0)
		{
			var date = new Date ();
			var dateExpires = new Date (date.getTime () + (this.options.expires * 1000))

			this.options.expires = '; expires=' + dateExpires.toGMTString ();
		}

		this.options.path.empty () || (this.options.path = '; path=' + escape (this.options.path));

		this.options.domain.empty () || (this.options.domain = '; domain=' + escape (this.options.domain));

		this.options.secure = this.options.secure == 'secure' ? '; secure' : '';
	},

	set : function (name, value)
	{
		switch (typeof (value))
		{
			case 'undefined' :
			case 'function' :
			case 'unknown' :
				return false;

				break;
			case 'boolean' :
			case 'string' :
			case 'number' :
				value = value.toString ();

				break;
		}

		try
		{
			document.cookie = name + "=" + escape (Object.toJSON (value)) + this.options.expires + this.options.path + this.options.domain + this.options.secure;
		}
		catch (e)
		{
			return false;
		}

		return true;
	},

	get : function (name)
	{
		var value = document.cookie.match (name + '=(.*?)(;|$)');

		return value ? (unescape (value[1])).evalJSON () : false;
	},

	remove : function (name)
	{
		try {
			var date = new Date (0);

			document.cookie = name + "=" + '; expires=' + date.toGMTString () + this.options.path + this.options.domain + this.options.secure;
		}
		catch (e)
		{
			return false;
		}

		return true;
	}
});