var RecentlyItems = {
	
	items : [],
	
	cookieValue : "",
	
	readCookie : function(qty)	{
		var cookieValue = "";
		var recentItems = [];
		var ck = document.cookie;
		
		if(ck.indexOf("SCRITEMS") != -1)	{
			ck = ck.split("SCRITEMS")[1].substring(1);
			var items = ck.split("SCRECENTLY");
			for(var a = 1; a <= qty && a < items.length; a++)	{
				var atts = items[a].split("/////");
				var newItem = { id : unescape(atts[0]), name : unescape(atts[1]), url : unescape(atts[2]), thumbnail : unescape(atts[3]), price : unescape(atts[4]) };
				recentItems.push(newItem);
				
				cookieValue += "SCRECENTLY" + atts[0] + "/////" + atts[1] + "/////" + atts[2] + "/////" + atts[3] + "/////" + atts[4];
			}
		}
		else	{
			return;
		}
		
		this.items = recentItems;
		this.cookieValue = cookieValue;
	},
	
	save : function(id, name, url, thumbnail, price)	{
		
		var its = this.items;
		var i = its.length;
		while(i--)	{
			if(id == its[i].id)	{
				return false;
			}
		}
		
		this.readCookie(2);
		document.cookie = "SCRITEMS=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
		
		var newItem = { id : id, name : name, url : url, thumbnail : thumbnail, price : price };
		this.items.unshift(newItem);
		
		var expires = new Date();
		expires.setTime( expires.getTime() + (60*24*60*60*1000) );
		expires = expires.toGMTString();
		var c = "SCRITEMS=SCRECENTLY" + escape(id) + "/////" + escape(name) + "/////" + escape(url) + "/////" + escape(thumbnail) + "/////" + escape(price) + this.cookieValue + "SCRITEMS" + ";path=/;expires=" + expires;
		document.cookie = c;
	},
	
	show : function(target, template)	{
		target = document.getElementById(target);
		this.readCookie(3);
		
		var its = this.items;
		var j = its.length;
		if(j == 0)	{
			target.style.display = "none";
			return;
		}
		
		for(var a = 0; a < j; a++)	{
			var itemHTML = template;
			itemHTML = itemHTML.replace(/<internalid>/gi, its[a].id);
			itemHTML = itemHTML.replace(/<storedisplayname>/gi, its[a].name);
			itemHTML = itemHTML.replace(/<storeurl>/gi, its[a].url);
			itemHTML = itemHTML.replace(/<storedisplaythumbnail>/gi, its[a].thumbnail);
			itemHTML = itemHTML.replace(/<salesprice>/gi, its[a].price);
			target.innerHTML += itemHTML;
		}
	}
	
}
