soundManager.waitForWindowLoad = true;
soundManager.url = 'swf/lib/';
soundManager.debugMode = false; 

flowplayer("player", "swf/lib/flowplayer-3.1.1.swf", {
	clip : {
		onStart: function() { stopAudios(); },
		onResume: function() { stopAudios(); }
	},
	playlist : [
		{url: "assets/captura.jpg", autoPlay: true},
		{url: "swf/video.flv", autoPlay: false}
	]
});

$("a.track_listen").live("click", function() {

	var wasPlaying = this.isPlaying;

	stopAudios();
	stopVideo();
	
	if(this.sound && !wasPlaying) {
		this.sound.play();
		this.isPlaying = true;
		
	}
	return false;
});


soundManager.onload = function() {
	$("a.track_listen")
		.each(function() {
			this.sound = soundManager.createSound(this.href, this.href);
			this.isPlaying = false;
		});
	$(".autoplay")
		.each(function() {
			this.sound.play();
			this.isPlaying = true;
	});
};

function stopAudios() {
	$("a.track_listen")
		.each(function() {
			if(this.sound) {
				this.sound.stop();
				this.isPlaying = false;
			}
		});
}

function stopVideo()  {
	flowplayer("player").stop();
}
