var RadioM80 = function(){
	this.rds_url = 'http://www.yes.fm/a/radio/M80Radio/getWhatsOn?';

	this.last_track = null;
	this.second_to_last_track = null;
	this.last_program = null;
	this.last_data = null;

	var e = new CustomEvent('new_radio', {'detail': {'radio': this}});
	document.dispatchEvent(e);
};

RadioM80.prototype = Object.create(Radio.prototype);
RadioM80.prototype.constructor = RadioM80 ;

RadioM80.prototype.radio_name = 'M80 Radio';
RadioM80.prototype.stream_url = 'http://13393.live.streamtheworld.com/M80RADIO_SC';
RadioM80.prototype.stream_mimetype = 'audio/mpeg';

RadioM80.prototype.get_current_track = function() {
	$.get(this.rds_url, this.m80_get_track.bind(this), 'json');
};

RadioM80.prototype.m80_get_track = function(data) {
	var program = data.radio.programaactual;

	if (!this.last_program || program.descripcion !== this.last_program.descripcion) {
		this.last_program = program;
		var e = new CustomEvent('new_program', {'detail': {'program': program.descripcion, 'banner': program.foto_fondo}});
		document.dispatchEvent(e);
	}

	var track = {name: data.radio.hasonado[0].track, artist:{name: data.radio.hasonado[0].artist}};


	if (this.last_track && track.name == this.last_track.name && track.artist.name == this.last_track.artist.name) {
		return;
	}

	/*
	 * Sometimes, when a song changes, the next request after the changes is the previous song. Keep two last songs to check for this and don't change the current track if the second to last was the same as the one we've got now
	 */
	if (this.second_to_last_track && track.name == this.second_to_last_track.name && track.artist.name == this.second_to_last_track.artist.name) {
		return;
	}

	this.second_to_last_track = this.last_track;
	this.last_track = track;
	var e = new CustomEvent('new_rds', {'detail': {'track': track}});
	document.dispatchEvent(e);
};

@@ -108,24 +108,48 @@
 ack = null;%0A
+%09this.last_date = null;%0A
 %09this.second
@@ -201,32 +201,8 @@
 ull;
-%0A%09this.last_data = null;
 %0A%0A%09v
@@ -788,16 +788,299 @@
 aactual;
+%0A%09var new_date = new Date();%0A%09var hhmm = data.radio.hasonado%5B0%5D.time.split(%22:%22);%0A%09new_date.setHours(hhmm%5B0%5D, hhmm%5B1%5D, 0, 0);%0A%09var now = new Date();%0A%0A%09if (new_date %3E now) %7B%0A%09%09console.log(%22M80: This song seems to have started yesterday%22);%0A%09%09new_date = new Date(newDate.getDate()-5);%0A%09%7D
 %0A%0A%09if (!
@@ -1437,17 +1437,16 @@
 ist%7D%7D;%0A%0A
-%0A
 %09if (thi
@@ -1565,16 +1565,158 @@
 rn;%0A%09%7D%0A%0A
+%09if (new_date %3C this.last_date) %7B%0A%09%09console.log(%22M80: This song is previous to the last song we've got!%22);%0A%09%09console.log(data);%0A%09%09return;%0A%09%7D%0A%0A
 %09/*%0A%09 * 
@@ -2172,16 +2172,44 @@
  track;%0A
+%09this.last_date = new_date;%0A
 %09var e =

Use the time reported by M80 to know if the song we receive es newer or older to the last we've got