var cookie = new (function() {

	var cash;
	var self = this;
	
	this.set = (
		function(name, value, expires, path, domain, secure)
		{
			var cook = name + "=" + encodeURIComponent(value);
			if (expires) {
				var t = new Date();
				t.setTime(t.getTime() + expires * 1000);
				cook += ";expires=" + t.toGMTString();
			}
			if (path) {
				cook += ";path=" + path;// + encodeURIComponent(path);
			} else if (path === undefined) {
				cook += ";path=/";
			}
			if (domain) {
				cook += ";domain=" + domain;
			}
			if (secure) {
				cook += ";secure";
			}
			document.cookie = cook;
			if (cash) {
				cash[name] = value;
			}
			return true;
		}
	);
	
	this.get = (
		function(name)
		{
			if (cash) {
				return cash[name];
			}
			self.parse();
			return cash[name];
		}
	);
	
	this.parse = (
		function()
		{
			cash = {};
			var cook = document.cookie;
			if (cook == '') return null;
			cook = cook.split(";");
			for (var i = 0; i < cook.length; i++) {
				var c = cook[i].split("=");
				if (c[1]) cash[c[0].replace(/^\s*/, "").replace(/\s*$/, "")] = decodeURIComponent(c[1].replace(/^\s*/, "").replace(/\s*$/, ""));
			}
		}
	);
	
	this.del = (
		function(name, path, domain)
		{
			self.set(name, "", -1, path, domain);
			if (cash) {
				cash[name] = undefined;
			}
			return true;
		}
	);

})();