PeriodicalExecuter.prototype.registerCallback = function() {
	this.intervalID = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
}

PeriodicalExecuter.prototype.stop = function() {
	clearInterval(this.intervalID);
}

var Spy = Class.create();
Spy.prototype = {
	data: spyInitData,
	pe: 0,
	interval: 15,
	status: 1,
	initialize: function () {
		this.fillHolder();
		this.pe = new PeriodicalExecuter(this.getNewData.bind(this), this.interval);
	},
	fillHolder: function () {
		this.data.each(function(item, index) {
			var holder = 'hold_' + index;
			if (index == 0) { 
				// EXPERIMENTAL ANIMATION
				Element.hide(holder);
				new Effect.Appear(holder);
				//new Effect.Highlight(holder, {startcolor: '#343A3B'}); 
			}
			$(holder).innerHTML = '<a href="' + item.userurl + '" rel="nofollow">' + item.username + '</a>' + ' on <a href="' + item.itemurl + '" rel="nofollow">' + item.itemname + '</a><br />' + item.comment + '....';
		});	
	},
	getNewData: function () {
		var showNewData = this.showNewData.bind(this);
		var url    = '/ajax/comment.php';
		var rand   = Math.random(9999);
		var lastid = this.data.first().id;
		var pars   = 'action=getspy&limit=5&id=' + lastid + '&rand=' + rand;
		var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onComplete: showNewData} );
	},
	showNewData: function (originalRequest) {
		//alert(originalRequest.responseText);
		this.data.unshift(eval('(' + originalRequest.responseText + ')'));
		this.data.pop();
		this.fillHolder();
	},
	playFunc: function () {
		if (this.status == 0) {
			this.pe = new PeriodicalExecuter(this.getNewData.bind(this), this.interval);
			this.status = 1;
		}
	},
	stopFunc: function () {
		this.pe.stop();
		this.status = 0;
	}
};

version = navigator.appVersion.match(/MSIE (\d)/);

if(version && (version[1] == 8 || version[1] == 7))
{
	ld = new Spy;
}
else
{
	document.observe("dom:loaded", function() {
		ld = new Spy;
	});
}