var MP3 = Class.create({
	player	: null,
	playing	: null,
	color	: null,
	
	initialize: function() {
	},

	go: function() { 
		this.player = document.createElement("span");
		document.body.appendChild(this.player);
		
		var a = $$("a");
		
		a.each(function(item) {
			if (item.href.match(/\.mp3$/i)) {
				item.onclick	= function(){mp3.play(this);return false;};
				item.onfocus	= function(){this.blur()};
			}
		});
		
	},

	play: function(o) { 
		if (this.playing == o) {
			this.player.innerHTML	= "";
			this.playing			= null;
			
			o.style.color  			= this.color;
		} else {
			if (this.playing)
				this.playing.style.color = this.color;
				
			this.player.innerHTML	= "<embed src='/files/mp3.swf' flashVars='theLink=" + o.href + "' quality='high' wmode='transparent' width='0' height='0' name='player' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";
			this.playing			= o;
			this.color				= o.style.color;
			
			o.style.color			= "#f00";
		}
	}
});

var	mp3 = new MP3();

Event.observe(window, 'load', function(event) {
	
	mp3.go();
});
