var AudioPlayer = function(){
}
AudioPlayer.prototype = {
	init: function(file,container){
		this.file = file;
		this.container = $(container);
		this.state = 'IDLE';
	},

	play: function(event,type) {
		Event.cancelEvent(event);
		this.type = type;

		if (!this.playerWindow) {
			this.open();
		} else {
			try {
				this.playerWindow.focus();
				var config = this.playerWindow.player.getConfig();
				if (config.state == 'PLAYING' && this.type == config.mode) {
					this.playerWindow.pause();
					this.resetButtons();
					return;
				} else {
					this.playerWindow.play(this.type);
				}
			} catch (e) {}
		}

		this.resetButtons();
		var el = Event.element(event);
		el.className += ' pause'
	},

	activateButton: function(type) {
		this.resetButtons();
		var el;

		var anchors = $$(this.container, 'a');
		for (var i = 0; i < anchors.length; i++) {
			if (anchors[i].className.match(type)) {
				el = anchors[i];
			}
		}
		el.className += ' pause'
	},

	resetButtons: function() {
		var anchors = $$(this.container, 'a');

		for (var i = 0; i < anchors.length; i++) {
			anchors[i].className = anchors[i].className.replace(/\spause/,'');
		}
	},

	unsetPlayerWindow: function() {
		this.playerWindow = undefined
	},

	open: function() {
		var e_url = '/i/swf/popupaudio.html?file=' + encodeURIComponent(this.file) + '&type=' + this.type;
		this.playerWindow = window.open(e_url,'openedWindow',"status=1,toolbar=0,menubar=0,location=0,resizable=0,scrollbar=0,width=255,height=89");
	}
}
