// radiochart.js -- Dudeplace's Radio Chart Component
// Written by Oo+
// require MooTools 1.2+

var RadioChart = new Class({
	Implements: [Events, Options],

	initialize: function(container, list, station, options) {
		this.setOptions(options);
		this.list = $(list);
		this.container = $(container);
		this.index = station;
		this.jaxon = new Jaxon({
			url: HOST_PATH + "/ajax/front/radiochart.php",
			method: 'get',
			wait: 'silent',
			onSuccess: function(text, tree, message, data) { this.load(tree, data); }.bind(this)
		});
		var head = this.container.getElement('.head');
		this.channel = head.getElement('.channel');
		head.getElement('.back').addEvent('click', this.back.bind(this));
		head.getElement('.next').addEvent('click', this.next.bind(this));
		this.jaxon.send("i=" + this.index + "&_" + $time());
		return this;
	},

	back: function() {
		var i = this.index - 1;
		this.jaxon.send("i=" + i + "&_" + $time());
		return this;
	},

	next: function() {
		var i = this.index + 1;
		this.jaxon.send("i=" + i + "&_" + $time());
		return this;
	},

	load: function(tree, data) {
		this.list.empty();
		if (data) {
			this.index = data.index;
			this.channel.set('text', data.channel);
			this.list.adopt(tree.getElements('li'));
		}
		else
			this.channel.set('text', "NO DATA");
		return this;
	},

	options: {
	}
});
