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

	options: {
		'container': null,
		'callback': "/modules/sn/scripts/getPlaylist.php"
	},

	container: null,

	initialize: function(options) {
		this.setOptions(options);
		this.container = $(this.options.container);
	},

	updatePlaylist: function() {
		var params = new Hash();
		new Request.JSON({
			url: this.options.callback,
			onComplete: function(jsonObj) {
				this.container.empty();

				var playlist = new Element("table", {});
				var playlist_table_body = new Element("tbody", {});

				jsonObj.each(function(item, key) {
					var row = new Element("tr", {});
					var hm = new Element("td", {'html': item.hoursminutes});
					if(key == 0) {
						hm.setStyle('font-weight', 'bold');
					}
					var artist = new Element("td", {'html': item.artist});
					var title = new Element("td", {'html': item.title});
					row.adopt(hm, artist, title);

					var brow = new Element("tr", {});
					var btd = new Element("td", {'colspan': 3});
					var div = new Element("div", {'class': "small-splitter"});

					btd.adopt(div);
					brow.adopt(btd);
					playlist_table_body.adopt(row);
					playlist_table_body.adopt(brow);
				}.bind(this));

				var search_tr = new Element("tr", {});
				var search_td = new Element("td", {'colspan': 3});
				var search_a = new Element("a", {'href': "/modules/sn/sn_playlist.php", 'html':"S&oslash;g i playlisten"});
				search_a.setStyles({'margin-bottom': "10px", 'color': "#3f8fa9"});
				search_a.setProperty('id', "searchlink");

				search_td.adopt(search_a);
				search_tr.adopt(search_td);
				playlist_table_body.adopt(search_tr);

				playlist.adopt(playlist_table_body);
				this.container.adopt(playlist);
			}.bind(this)
		}).post(params);
	}
});

