var listener = new Object();

/**
* Initialisation
 */
 
listener.onInit = function()
{
		this.position = 0;
		this.pl = 0;
};

/**
* 
 */
listener.onUpdate = function()
{

}

function getFlashObject()
{
	return document.getElementById("player");
}

function playThis(obj,songId){

/*	alert(songId);*/

	stopAll();

/*	$(obj).click(function(){
		stopThis(this);
	});
*/

	obj.innerHTML = '';
	
	songPath = $('#mp3Href_'+songId).attr('href');
	$(obj).attr('class', 'player-stop');
	if( listener.isPlaying == 'true' ){
		stopThis(obj);
	} else {

		play(songPath);
	}

}

function play(songPath)
{
	getFlashObject().SetVariable("method:setUrl", songPath);
	getFlashObject().SetVariable("method:play", "");
	getFlashObject().SetVariable("enabled", "true");
	playing = 1;
}

function pause()
{
	getFlashObject().SetVariable("method:pause", "");
	playing = 0;
}

function stopThis(obj){
	obj.innerHTML = '';
	$(obj).attr('class', 'player-play');
/*	$(obj).click(function(){
		playThis(this, $(obj).attr('id').split("_")[1]);
	});*/
	stop();

}

function stopAll(){
	$('.songs-mp3-button span').each(function(){
		$(this).attr('class', 'player-play');
//		$(this).html('play');
	});
	playing = 0;
}

function stop()
{
	getFlashObject().SetVariable("method:stop", "");
	playing = 0;
}

/*

var listener = new Object();
var playing = 0;

// Initialisation

listener.onInit = function()
{
		this.position = 0;
		this.pl = 0;
};

var self = this;

listener.onUpdate = function()
{
	document.getElementById('dezd').innerHTML = this.url;
	document.getElementById('dezd2').innerHTML = this.position+' == '+this.duration;
	
	if( playing == 1 && this.position == 0 ){
		self.playNext(this.url);
	}

}

function getFlashObject()
{
	return document.getElementById("player");
}


function playThis(obj,songId){

	stopAll();

	$(obj).click(function(){
		stopThis(this);
	});

	obj.innerHTML = 'stop'
	
	songPath = $('#mp3Href_'+songId).attr('href');
	play(songPath);

}

function stopAll(){
	$('#mp3-list span').each(function(){
		$(this).html('play');
	});
	playing = 0;
}

function stopThis(obj){
	obj.innerHTML = 'play';
	stop();
}

function playNext(mp3Path){

	stopAll();

	songIdStr = $("a[href='"+mp3Path+"']").attr('id');
	songId = songIdStr.split("_")[1];

	playNext = 0;
	found = 0;

	$('#mp3-list span').each(function(i){
		if( playNext == 1 ){
			found = 1;
			$(this).click();
			playNext = 0;
		}
		if( $(this).attr('id') == 'song_'+songId ){
			playNext = 1;
		}
	});
	
	if( found == 0){
		$("#mp3-list span:first").click();
	}

}

function play(songPath)
{
	getFlashObject().SetVariable("method:setUrl", songPath);
	getFlashObject().SetVariable("method:play", "");
	getFlashObject().SetVariable("enabled", "true");
	playing = 1;
}

function pause()
{
	getFlashObject().SetVariable("method:pause", "");
	playing = 0;
}

function stop()
{
	getFlashObject().SetVariable("method:stop", "");
	playing = 0;
}
*/