var activeAudioId = null;
var activePlayerColorVariant = null
var audioPlayerName = "audioHukPlayer";

function playAudioContent( song, itemId, colorVariant ) {
	startPlaying = true;
	
	if( activeAudioId == itemId || ( activeAudioId != null && activeAudioId != itemId )){
		if( activeAudioId == itemId ) {
			startPlaying = false;
		}
		$f(audioPlayerName).stop();
	}

	if( startPlaying )  {
		
		activeAudioId = itemId;
		activePlayerColorVariant = colorVariant;
		
		$f(audioPlayerName).play({
			url:song,
		});
	}
}

function updatePlayerIcon(hasStarted){
	if( hasStarted == true ) {
		$('#'+activeAudioId).attr({
			src: "http://static.eskalivermx.pl/webapps/front/html/img/ico_stop_"+activePlayerColorVariant+".gif",
		});
	} else {
		$('#'+activeAudioId).attr({
			src: "http://static.eskalivermx.pl/webapps/front/html/img/ico_audio_"+activePlayerColorVariant+".gif",
		});
		activeAudioId = null;
		activePlayerColorVariant = null;
	}
}

$f( audioPlayerName, 'http://static.eskalivermx.pl/webapps/front/html/javascript/flowplayer/flowplayer-3.0.7.swf', {
	clip: {
    	autoBuffering: true,
    	autoPlay: true,
		onBegin: function() {
			this.setVolume(80);
			updatePlayerIcon(true);
		},
		onStart: function() {
			this.setVolume(80);
			updatePlayerIcon(true);
		},
		onStop: function() {
			updatePlayerIcon(false);
		},
    	onFinish: function(clip) {
			updatePlayerIcon(false);
		}
	},
	onLoad: function(clip) {
		this.hide();
	},
	plugins: {
		audio: {
    		url: 'http://static.eskalivermx.pl/webapps/front/html/javascript/flowplayer/flowplayer.audio-3.0.4.swf' 
		}, 
		controls: {
			playlist: false,
			fullscreen: false
		}
	}
});