var audioPlayer, playerElement=0, thesong;
var volume = 100, oldVolume = 0, waitForAudioPlayer = 0;		

function playerReady(p) {
	if (waitForAudioPlayer == 0) return;
	waitForAudioPlayer = 0;
	playerElement = document.getElementById(p.id);
	}

function initAudio(song) {
	thesong = song;
	waitForAudioPlayer = 1;
	audioPlayer = new SWFObject('media/JWPlayer/player.swf','player','0','0','9');

	audioPlayer.addParam('allowscriptaccess','always');

	audioPlayer.addVariable('file', song);
	audioPlayer.addVariable('controlbar', 'none');
	audioPlayer.addVariable('autostart', 'true');
	audioPlayer.addVariable('repeat', 'always');
	audioPlayer.addVariable('volume', volume);
	audioPlayer.write('audioplayer');
	}

function stopAudio() {
	if (!playerElement) {
		audioPlayer.addVariable('file', '');
		audioPlayer.write('audioplayer');
		volume=0;
		document.getElementById('musicOff').style.display = 'none';
		document.getElementById('musicOn').style.display = 'block';
		return;
		}
	if (volume == 0) {
		playerElement.sendEvent('STOP');
		document.getElementById('musicOff').style.display = 'none';
		document.getElementById('musicOn').style.display = 'block';
		return;
		}
	volume -= 20;
	playerElement.sendEvent('VOLUME', volume);
	setTimeout('stopAudio()', 100);
	}

function restartAudio() {
	if (!playerElement) {
		audioPlayer.addVariable('file', thesong);
		audioPlayer.write('audioplayer');
		volume=100;
		document.getElementById('audioplayer').style.display = 'block';
		document.getElementById('musicOn').style.display = 'none';
		document.getElementById('musicOff').style.display = 'block';
		return;
		}
	if (volume == 0) {
		playerElement.sendEvent('PLAY');
		}
	if (volume == 100) {
		document.getElementById('musicOn').style.display = 'none';
		document.getElementById('musicOff').style.display = 'block';
		return;
		}
	volume += 20;
	playerElement.sendEvent('VOLUME', volume);
	setTimeout('restartAudio()', 100);
	}

