function Cache (id,exp)
{
	this.exp = new Date();
	this.exp.setTime(exp);
	this.id = id;
	this.initialised = false;
	this.enabled = true;
	this.size = 4096;//3.7k cache for cookie based caching. IE get's a larger userdata store
	this.initialise = function()
	{
		var elm = document.createElement('div');
		document.body.appendChild(elm);
		//Store cache in userData for IE. The data store is bigger
		if(typeof elm.style.behavior != 'undefined')
		{
			try
			{
				elm.style.behavior='url(#default#userData)';
				this.elm = elm;
				this.size = 60000;
				this.elm.load(this.id);
			}
			catch(ex){}
		}
		else
		{
			document.body.removeChild(elm);
		}
		this.initialised = true;
	};
	this.reload = function()
	{
		if(this.elm)
			document.body.removeChild(this.elm);
		this.initialised = false;
		this.elm = null;
	};
	this.setCookie = function(name, value, expires)
	{
		document.cookie=name+'='+escape(value)+";path=/"+((expires==null)?"":";expires="+expires.toGMTString());
	};
	this.getCookie = function (name){
		var cname=name+"=";
		var dc=document.cookie;
		if (dc.length>0)
		{
			begin=dc.indexOf(cname);
			if (begin!=-1)
			{
				begin+=cname.length;
				end=dc.indexOf(";",begin);
				if(end==-1)
					end=dc.length;
				if(dc.substring(begin,end)!='false')
					return unescape(dc.substring(begin,end));
				else
					return null;
			}
		};
		return null;
	};
	this.deleteCookie = function(name){
		document.cookie=name+"=;expires=Thu,01-Jan-70 00:00:01 GMT"+";path=/";
	};
	this.get = function(name,encrypted)
	{
		if(!this.enabled)return false;
		if(!this.initialised)this.initialise();
		if(this.elm && !this.getCookie(name))
		{
			try
			{
				var val = this.elm.getAttribute(name);
				//if(val && encrypted)val = Base64.decode(val);
				if(!val)this.reload();
				return val;
			}
			catch(ex)
			{
				return false;
			}
		}
		else
		{
			var val = this.getCookie(name);
			//if(encrypted)val = Base64.decode(val);
			return val;
		}
	};
	/*
		Pass in name, value and whether to encrypt the value
		force = true means force to (attempt) to store no matter what the size
	*/
	this.store = function(name,value,encrypt,force)
	{
		if(!this.enabled)
			return;
		if(!this.initialised)this.initialise();
		//Base64 encode the value to store - so it doesn't look bad
		//if(encrypt)
			//value = Base64.encode(value);
		//Store in user data if IE
		if((value.toString().length < this.size) && this.elm)
		{
			if(this.elm.getAttribute(name))
				this.elm.removeAttribute(name);
			this.elm.setAttribute(name,value);
			this.elm.expires = this.exp.toUTCString();
			try
			{
				this.elm.save(this.id);
			}
			catch(ex)
			{
				return false;
			}
		}
		//Else store in a cookie, if it'll fit
		else if((document.cookie.length + escape(value.toString()).length < 3.6 * 1024) || force)
			this.setCookie(name,value,this.exp);
	};
};