﻿function playSound (mp3file, oggfile, wavefile)
{
	if (mp3file != null && detectHTML5("audio/mpeg"))
		playSoundHTML5(mp3file);
	else if (oggfile != null && detectHTML5("audio/ogg"))
		playSoundHTML5(oggfile);
	else if (wavefile != null && detectHTML5("audio/wav"))
		playSoundHTML5(wavefile);
	else if (mp3file != null && swfobject.hasFlashPlayerVersion("7.0.0"))
		playSoundFlash7(mp3file);
	else
		alert("Denne funktion kræver Flash eller HTML 5");
}

function detectHTML5 (mimeType)
{
	try
	{
		if (navigator.appVersion.indexOf("Chrome/") != -1)
			return false;
		if (window.Audio)
		{
			var audio = new Audio();
			if (audio.canPlayType(mimeType))
				return true;
		}
	}
	catch (e)
	{
	}
	return false;
}

function playSoundHTML5 (url)
{
	var audio = new Audio();
	audio.loop = false;
	audio.controls = false;
	audio.autoplay = true;
	audio.autobuffer = true;
	audio.src = url;
	audio.load();
}

function playSoundFlash7 (mp3file)
{
	var url = "/swf/play.swf?soundfile="+escape(mp3file)+"&random="+Math.random();
	var flashvars = {};
	var params = {
		"play":"true",
		"loop":"false",
		"menu":"false",
		"quality":"autohigh",
		"scale":"default",
		"allowscriptaccess":"never",
		"allownetworking":"all",
		"allowfullscreen":"false"
	};
	var attributes = {};
	var flashvars = [];
	var audioObj = document.createElement("div");
	audioObj.id = "audioObj";
	document.body.appendChild(audioObj);
	swfobject.embedSWF(url, "audioObj", "0", "0", "7.0.0", null, flashvars, params, attributes, function (e) { if (!e.success) alert("Der opstod en fejl under initialisering af Flash"); });
}

