var AudioPlayer = new function(){
	this.FlashAudioPlayer = null;
	this.url = null;
	this.isPlaying = null;
	this.volume = null;
	this.position = null;
	this.duration = null;
	this.bytesLoaded = null;
	this.bytesTotal = null;
	this.bytesPercent = null;
	var fn_playStop, playStop = function(){if(typeof(fn_playStop)=='function'){fn_playStop();fn_playStop=null;}};
	
	this.onInit = function(){
		this.FlashAudioPlayer = document.getElementById("FlashAudioPlayer");
		this.position = 0;
	};
	
	this.onUpdate = function(){
		if (this.position==0 || this.position==this.duration) playStop();
	};

	this.play = function(url, cb_playStop){
		if (url || AudioPlayer.position == 0) {
			this.FlashAudioPlayer.SetVariable("method:setUrl", url);
		}
		this.FlashAudioPlayer.SetVariable("method:play", "");
		this.FlashAudioPlayer.SetVariable("enabled", "true");
		fn_playStop = cb_playStop;
	};
	
	this.pause = function(){
		this.FlashAudioPlayer.SetVariable("method:pause", "");
	};
	
	this.stop = function(){
		this.FlashAudioPlayer.SetVariable("method:stop", "");
		playStop();
	};
	
	this.setPosition = function(position){
		this.FlashAudioPlayer.SetVariable("method:setPosition", position);
	};
	
	this.setVolume = function(volume){
		this.FlashAudioPlayer.SetVariable("method:setVolume", volume);
	};
};

var CdSampler = new function(){
	var activeNode;
	var deactivateNode = function(){
		if (activeNode){activeNode.className = 'player_play'; activeNode = null;}
	};
	this.play = function(node, url){
		if (node.className == 'player_play'){
			this.stop();
			AudioPlayer.play(url, deactivateNode);
			if (node.tagName == 'A'){
				node.className = 'player_stop';
				activeNode = node;
			}
		}else this.stop();
	};
	this.stop = function(){
		AudioPlayer.stop(); deactivateNode();
	};
};