
var PLAYER_URL  = "PodPlayer.swf";
var CURRENT_PODCAST_URL = null;
var CURRENT_START_BUTTON = null;
var CURRENT_STOP_BUTTON = null;
// podcast should look like: "2006/drums-and-drumming"
function startAudio(podcast, startButtonId, stopButtonId) {
	showProgressEvent = false;
	if (CURRENT_PODCAST_URL != null) {
		stopAudio();
	}
	CURRENT_PODCAST_URL = podcast;
	CURRENT_START_BUTTON = document.getElementById(startButtonId);
	CURRENT_STOP_BUTTON = document.getElementById(stopButtonId);
	
	CURRENT_START_BUTTON.style.display = "none";
	CURRENT_STOP_BUTTON.style.display = "";
	flashVars = ["soundId=podcast&soundURL=" + escape(CURRENT_PODCAST_URL)];
	getAudioDiv().innerHTML = [
		'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"',
		'		codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"',
		'		WIDTH="0"',
		'		HEIGHT="0"',
		'       id="SamplePlayer">',
		'	<PARAM NAME=movie VALUE="' + PLAYER_URL + '">',
		'	<PARAM NAME=quality VALUE=high>',
		'	<PARAM NAME=bgcolor VALUE=#FFFFFF>',
		'	<PARAM NAME=menu VALUE=false>',
		' <PARAM NAME="FlashVars" VALUE="' + flashVars + '">',
		'<EMBED src="' + PLAYER_URL + '"',
		'       quality=high',
		'       bgcolor=#FFFFFF',
		'       WIDTH="0"',
		'       HEIGHT="0"',
		'       MENU="false"',
		'       NAME="SamplePlayer" ALIGN="" TYPE="application/x-shockwave-flash"',
		'       PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"',
		'       FlashVars="' + flashVars + '">',
		'</EMBED>',
		'</OBJECT>'
	].join("");
}

function stopAudio() {
	CURRENT_PODCAST_URL = null;
	if (CURRENT_START_BUTTON != null) {
		CURRENT_START_BUTTON.style.display = "";
		CURRENT_START_BUTTON = null;
	}
	if (CURRENT_STOP_BUTTON != null) {
		CURRENT_STOP_BUTTON.style.display = "none";
		CURRENT_STOP_BUTTON = null;
	}
	getAudioDiv().innerHTML = "";
	
}

function getAudioDiv() {
	var div = document.getElementById("audioDiv");
	if( div == null ) {
		div = document.createElement("DIV");
		div.id = "audioDiv";
		document.documentElement.appendChild(div);
	}
	return div;
}

function onSoundLoad(id, success) {
	if (!success) {
		stopAudio();
	}
}

function onSoundComplete() {
	stopAudio();
}

//Setup MouseOver graphics
var play_up = new Image(24,24); play_up.src = "img/play2.gif";
var stop_up = new Image(24,24); stop_up.src = "img/stop2.gif";
var load_up = new Image(24,24); load_up.src = "img/load2.gif";
var play_dn = new Image(24,24); play_dn.src = "img/play_hover2.gif";
var stop_dn = new Image(24,24); stop_dn.src = "img/stop_hover2.gif";
var load_dn = new Image(24,24); load_dn.src = "img/load_hover2.gif";

function buttonHover() { //provide mouseover
	var args=buttonHover.arguments, button = args[0], state = args[1], buttonControl;       
        if ((buttonControl=MM_findObj(button))!=null) {
		var buttonState = eval(state);
        	buttonControl.src = buttonState.src;
        }
}