var myListener = new Object();

var albums = new Array(
	"Montana Beach",
	"Scotch"
);
var songs = new Array(
	new Array("Verino", "Fago", "Drowsy Maggie", "Mannborg", "Daar Staat de Zee", "Warsaw Ghetto", "Nicky Tempts", "Presidente", "Simon de Danser", "Kabouternummer", "Urban Explorer Walz"),
	new Array("Ladyfest", "Maanfluiter", "Pop", "Godfather", "El Heffe", "B2", "Guacamole", "Greed", "Outro")
);

/**
 * Initialisation
 */
myListener.onInit = function()
{
	this.position = 0;
	this.albumId = 0;
	this.songId = 0;
	this.setTitle();
	this.url = '';
};
/**
 * Update
 */
myListener.onUpdate = function()
{
	var isPlaying = (this.isPlaying == "true");
	document.getElementById("playerplay").style.display = (isPlaying)?"none":"block";
	document.getElementById("playerpause").style.display = (isPlaying)?"block":"none";

	this.setTitle();
};
myListener.setTitle = function() {
	var artist = "Scotch";
	var album = albums[this.albumId];
	var title = songs[this.albumId][this.songId];
	document.getElementById("info_title").innerHTML = artist + " - " + album + " - " + this.getTrack() + " - " + title;
}
function getFlashObject()
{
	return document.getElementById("musicPlayer");
}
function play()
{
	if (myListener.currentlyPlaying == null) myListener.setSong();
	getFlashObject().SetVariable("method:play", "");
	getFlashObject().SetVariable("enabled", "true");
}
myListener.getTrack = function() {
	var nr = this.songId+1;
	return nr < 10 ? "0" + nr : nr;
}
myListener.setSong = function () {
	this.getTrack(this.songId);
	var newUrl = '/music/' + albums[this.albumId] + '/' + this.getTrack() + "-" + songs[this.albumId][this.songId] + ".mp3";
	if (this.currentlyPlaying != newUrl) {
		getFlashObject().SetVariable("method:setUrl", newUrl);
		this.currentlyPlaying = newUrl;
		if (this.isPlaying == "true") {
			getFlashObject().SetVariable("method:stop", "");
			getFlashObject().SetVariable("method:play", "");
		}
	}
}
function pause()
{
	getFlashObject().SetVariable("method:pause", "");
}
function stop()
{
	getFlashObject().SetVariable("method:stop", "");
}
function setPosition()
{
	var position = document.getElementById("inputPosition").value;
	getFlashObject().SetVariable("method:setPosition", position);
}
function setVolume()
{
	var volume = document.getElementById("inputVolume").value;
	getFlashObject().SetVariable("method:setVolume", volume);
}
function nextSong() {
	if (songs[myListener.albumId].length - 1 == myListener.songId) {
		// next album
		myListener.songId = 0;
		myListener.albumId = (myListener.albumId+1) % albums.length;
	} else {
		myListener.songId++;
	}
	myListener.setTitle();
	myListener.setSong();
}
function prevSong() {
	if (myListener.songId == 0) {
		// prev album
		myListener.albumId--;
		if (myListener.albumId<0) myListener.albumId = albums.length - 1;
		myListener.songId = songs[myListener.albumId].length - 1;
	} else {
		myListener.songId--;
	}
	myListener.setTitle();
	myListener.setSong();
}

