var isPlaying=0;
var MP3filePlaying="";
var MM_FlashCanPlay=0;
var MM_ContentVersion = 6;
var browserType='';
var browserTypeOK=false;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

if ( plugin ) {
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i]))) continue;
		var MM_PluginVersion = words[i]; 
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_ContentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
	str='';
	str+='<SCR' + 'IPT LANGUAGE=VBScript\> \n'; //FS hide this from IE4.5 Mac by splitting the tag
	str+='on error resume next \n';
	str+='MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_ContentVersion)))\n';
	str+='</SCR' + 'IPT\> \n';
	document.write(str);
}

function checkBrowser() {
///////////////////////
	if (document.layers) browserType='ne'
	else {
		if (document.all) browserType='ie'
		else {
			if (document.getElementById) browserType='ne6'; 
		}
	}
	browserTypeOK=(browserType!='');
}

checkBrowser();

function writeIntoLayer(id,txt) {
///////////////////////////////
	if (!browserTypeOK) return;
	switch (browserType) {
	case ('ne') : 
		document.layers[id].document.open();
		document.layers[id].document.write(txt);
		document.layers[id].document.close()
		break;
	case ('ie') :	
		document.all[id].innerHTML=txt;
		break;
	case ('ne6') :
		document.getElementById(id).innerHTML=txt;
		break;
	}
}

function codeFlash(MP3file,loop) {
///////////////////////////////
	str="";
	flashFile='mp3player.swf';
	swfString=flashFile+'?audiofile='+MP3file;
	if (!isNaN(loop)) swfString+='&loopaudio=1'
	if ( MM_FlashCanPlay ) {
		str+='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ID="mp3" WIDTH="0" HEIGHT="0" ALIGN="">';
		str+='<PARAM NAME=movie VALUE="'+swfString+'"><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><param name=play value=1>'; 
		str+='<EMBED src="'+swfString+'" quality=high bgcolor=#FFFFFF swLiveConnect=true WIDTH="0" HEIGHT="0" NAME="mp3" ALIGN=""';
		str+='TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
		str+='</EMBED>';
		str+='</OBJECT>';
	}
	return str;
}

function playMP3(MP3file,loop) {
/////////////////////////////
	if (isPlaying==0) {
		document.write('<div id="MP3Player">'+codeFlash(MP3file,loop)+'</div>');
		isPlaying=1;
	}
	MP3filePlaying=MP3file;
}

function togglePlayMP3(MP3file,loop) {
////////////////////////////////////
	if (isPlaying==1) {
		if (MP3filePlaying==MP3file) { 
			writeIntoLayer('MP3Player',""); //same file so stop it
			isPlaying=0;
		} 
		else {
			writeIntoLayer('MP3Player',codeFlash(MP3file,loop)); //different file so play it	
			isPlaying=1;
		}
	}
	else {
		writeIntoLayer('MP3Player',codeFlash(MP3file,loop)); //stopped so play it
		isPlaying=1;
	}
	MP3filePlaying=MP3file;
}

function togglePlayMP3Pic(MP3file,loop,imgName,srcOn,srcOff) {
////////////////////////////////////////////////////////////
	if (isPlaying==1) {
		writeIntoLayer('MP3Player',"");
		document.images[imgName].src=srcOff;
		isPlaying=0;
		}
	else {
		writeIntoLayer('MP3Player',codeFlash(MP3file,loop))
		document.images[imgName].src=srcOn;
		isPlaying=1;
	}
	MP3filePlaying=MP3file;
}
