String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}
String.prototype.beginsWith = function(str)
{return (this.match("^"+str)==str)}

var alle_audio = [];

function maakAudioTag(element)
{
	var src = $(element).attr("href");
	
	var audio_test = new Audio();
	if (!audio_test.canPlayType) return false;
	if (audio_test.canPlayType("audio/ogg; codecs=vorbis") != "")
	{
		src = src.replace(".mp3", ".ogg");
		$(element).attr("href", src);
	}
	else if (audio_test.canPlayType("audio/mpeg") == "")
	{
		return false;
	}
	
	audio_test = null;
	
	var l_id = src + "-link";
	var a_id = src + "-audio";
	
	$(element).wrap("<span/>");
	
	var audio = new Audio(src); audio.id = a_id;
	alle_audio.push(audio);
	
	$(element).before(audio);
		
	$(element).addClass("audio-play");
	$(element).attr("id", l_id);
	
	$(element).click(function()
	{
		if ($(element).hasClass("audio-play"))
		{
			for (a in alle_audio)
			{
				alle_audio[a].pause();
				$(alle_audio[a]).parent().children("a").removeClass("audio-pause");
				$(alle_audio[a]).parent().children("a").addClass("audio-play");
			}
			
			audio.play();
			$(element).removeClass("audio-play");
			$(element).addClass("audio-pause");
		}
		else if ($(element).hasClass("audio-pause"))
		{
			audio.pause();
			$(element).removeClass("audio-pause");
			$(element).addClass("audio-play");
		}
		
		return false;
	});
}
