function MediaPlayer(javascriptId, songs)
{
	this.javascriptId = javascriptId;
	this.currentSong = false;
	this.playingSong = false;
	this.songs = songs;

	this.playSong = function(song) { sendEvent(this.javascriptId, 'playitem', song); };
	this.stop     = function()     { sendEvent(this.javascriptId, 'stop'); };



	/**
	 * This function gets called by the when a new song gets handled.
	 */
	this.setCurrentSong = function(song)
	{
		if (this.currentSong !== song)
		{
			this.playingSong = false;
			this.setStopped();
		}
		this.currentSong = song;
	};


	/**
	 * This function gets called by the mediaplayer on stop.
	 */
	this.setStopped = function()
	{
		var self = this;
		// this.currentSong = false;
		this.playingSong = false;

		this.songs.each(function(songInfos)
		{
			self.setSongStopped(songInfos.id, songInfos.elementId);
		});
	};

	this.setSongStopped = function(song, elementId)
	{
		$(elementId + 'Play').show();
		$(elementId + 'Stop').hide();
	};
	this.setSongPlaying = function(song, elementId)
	{
		$(elementId + 'Play').hide();
		$(elementId + 'Stop').show();
	};

	/**
	 * This function gets called by the mediaplayer when a song starts.
	 */
	this.setPlaying = function()
	{
		if (!this.playingSong)
		{
			var songId = this.currentSong;
			var self = this;
			this.songs.each(function(songInfos)
			{
				if (songInfos.id == songId)
				{
					self.setSongPlaying(songInfos.id, songInfos.elementId);
				}
			});

			this.playingSong = true;
		}
	};
}
