function _ArturoUnread() {
	//
	// Support utilities
	//
	this.setCookie = function(cName, cValue, days) {
		if (!days) { days = 1; }
		var startDate = new Date(); var utime = startDate.getTime();
		startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0);
		var expDate = new Date(startDate.getTime()+(86400 * 1000 * days));
		var max_age = parseInt((expDate.getTime()- utime) / 1000);

		// build the cookie string
		var c = cName+"="+escape(cValue)+"; max-age="+max_age+"; expires="+expDate.toGMTString()+"; path=/;";
		document.cookie = c;
		return true
	}

	this.getCookie = function(name) {
		var cookieData = document.cookie;
		var start = cookieData.indexOf(name + "=");
		var len = start + name.length + 1;
		if ((!start) && (name != cookieData.substring(0, name.length))) {
			return '';
		}
		if (start == -1) { return ''; }
		var end = cookieData.indexOf(';', len);
		if (end == -1) { end = cookieData.length; }
		return unescape(cookieData.substring( len, end ));
	}

	this.unique = function(a) {
	   var r = new Array();
	   o:for(var i = 0, n = a.length; i < n; i++) {
		  for(var x = 0, y = r.length; x < y; x++) {
			 if(r[x]==a[i]) continue o;
		  }
		  r[r.length] = a[i];
	   }
	   return r;
	}

	this.loadStoredInfo = function() {
		if (this.storage) {
			try	{
				this.readInfo = new String(this.storage.AReadInfo).replace("undefined","").split("|") || new Array();
			} catch (e) { }
		} else {
			try	{
				this.readInfo = this.getCookie("AReadInfo").split("|") || new Array();
			} catch (e) { }

		}
	}

	this.saveStoredInfo = function() {
		var r = this.unique(this.readInfo).join("|").replace("undefined|","");
		if (this.storage) {
			this.storage.AReadInfo = r;
		} else {
			this.setCookie("AReadInfo", r, 2);
		}

	}

	this.isUnread = function(idx) {
		idx = new String(idx).replace("am-","");
		if (!this.readInfo.length) { return true; }
		if (!idx || idx == "v") return false;
		// codice di limite per vg.it
		if (parseInt(idx) && parseInt(idx) < 79900) { return false; }
		else if (parseInt(idx.replace("v","")) && parseInt(idx.replace("v","")) < 3850) { return false; }

		var l = this.readInfo.length;
		for (i = 0; i < l; i++) {
			if (this.readInfo[i] == idx) { return false; }
		}
		return true;
	}


	this.setRead = function(idx) {
		var id = new String(idx).replace("am-","")
		this.readInfo.push(id);
		this.saveStoredInfo()
	}

	this.markUnread = function() {
		var el = null;
		var el_list = window.jQuery(".ArturoUnread");
		for (var i = 0; i < el_list.length; i++) {
			el = el_list.eq(i);
			if (this.isUnread(el.get(0).id)) {
				el.addClass("Unread");
				if (el.hasClass("number")) {
					el.append('<img src="/arturo/www/siti/next5/unread.png" alt="" />');
				}
			}
		}
	}

	this.markAllRead = function() {
		var el = null;
		var id = "";
		var el_list = window.jQuery(".ArturoUnread");
		for (var i = 0; i < el_list.length; i++) {
			id = new String(el_list.eq(i).get(0).id).replace("am-","")
			if (!id || id == "v" || id == "undefined") { continue; }
			this.readInfo.push(id);
		}
		this.saveStoredInfo();
		window.jQuery("td.number.Unread img").remove();
		window.jQuery(".Unread img").removeClass("Unread");
	}

	try	{ this.hostname = window.location.hostname; }
	catch (e) { }
	if (!this.hostname) { this.hostname = "videogame.it"; }
	this.storage = null;
	if (window.globalStorage) { this.storage = window.globalStorage[this.hostname]; }
	else if (window.localStorage) { this.storage = window.localStorage[this.hostname]; }
	else if (window["localStorage"]) { this.storage = window["localStorage"][this.hostname]; }

	this.readInfo = new Array();
	this.loadStoredInfo();
}

window.ArturoUnread = new _ArturoUnread();
