﻿var aapa; // aapa = activate audio player anchor [tag]
var aapa_last;
var aapa_text_default;
var aapa_border_default;
var aapa_backgroundColor_default;
function activateAudioPlayer(aapa) {
	if ( document.getElementById( "audio_player" ) ) {
		if ( aapa.parentNode == document.getElementById( "audio_player" ).parentNode ) { deActivateAudioPlayer(aapa); }
		else { deActivateAudioPlayer( document.getElementById( "audio_player" ).parentNode.getElementsByTagName( "a" )[0] ); createAudioPlayer(aapa); }
		} 
	else { createAudioPlayer(aapa); }
	return false;
	}
function deActivateAudioPlayer( aapa_last ) {
	document.audioListen.Stop();
	document.getElementById( "audio_player" ).parentNode.removeChild( document.getElementById( "audio_player" ) );
	aapa_last.innerHTML = aapa_text_default;
	aapa_last.style.border = aapa_border_default;
	aapa_last.style.backgroundColor = aapa_backgroundColor_default;
	}
function createAudioPlayer(aapa) {
	aapa.parentNode.appendChild( document.createElement("div")).id = "audio_player";
//	alert( aapa.parentNode.offsetWidth );
	ap = document.getElementById( "audio_player" );
	nuwidth   = aapa.parentNode.offsetWidth - 20;
	ap.style.width = nuwidth > 360 ? "360px" : nuwidth+"px" ;
	ap.style.padding = "5px";
	ap.style.border = "2px solid #999";
	aapa_border_default = aapa.style.border;
	aapa_backgroundColor_default = aapa.style.backgroundColor;
	aapa.style.backgroundColor = ap.style.borderTopColor;
	aapa.style.padding = ap.style.borderTopWidth;
	ap.innerHTML = '<embed name="audioListen" src="'+aapa.href+'" autostart="true" loop="false" volume="100" height="16" width="100%"></embed><p class="note" style="text-align: center; font-style: normal;">'+aapa.title.replace(/ -- /g,'<br />')+'</p>';

	aapa_text_default = aapa.innerHTML;
	
	aapa.innerHTML = "stop player…";
	}