$(document).ready(function(){    
	$('#casusContainer').spy({
		limit: 20,
		fadeLast: 8, 
		timeout: 2000, 
		ajax: 'casus/casus', 
		push: custom_push, 
		method: 'json', 
		isDupe: myIsDupe });  
});

function custom_push(response){
	var json = response;
	var html = '<div><span class="ctr">';
	html += '<font color="#808080">' + myTimestamp() + '</font> ' + '<b>' + stripslashes(json.num) + '</b> </span><span class="content">';
	html += stripslashes(json.string) + '</span></div>';
	$('#' + this.id).prepend(html);
}

function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function myIsDupe(latest, last) {
  return !!(latest.id == last.id); // return boolean
}

function myTimestamp() {
  	var d = new Date();
  	return pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
}

function pad(n) {
  n = n.toString();
  return n.length == 1 ? '0' + n : n;
}
