if (!window.Vanilla){
var Vanilla = new PathFinder();
Vanilla.webRoot = Vanilla.getRootPath('script', 'src', 'js/global.js');
Vanilla.styleUrl = Vanilla.getRootPath('link', 'href', 'vanilla.css');
Vanilla.baseURL = Vanilla.params.httpMethod + Vanilla.params.domain + Vanilla.webRoot;
}

if(typeof(btp) == 'undefined') btp = {}
btp.Mp3 = {
	playimg: null,
	player: null,
	go: function() {
		var all = document.getElementsByTagName('a')
		for (var i = 0, o; o = all[i]; i++) 
		{
			if(o.href.match(/\.mp3$/i)) 
			{
				var img = document.createElement('img')
				img.src = Vanilla.webRoot+'extensions/Dplayer/off.gif';
				img.title = ''
				img.height = 27
				img.width = 74
				img.style.marginRight = '0.2em'
				img.style.cursor = 'pointer'
				img.style.verticalAlign = 'middle'
				img.style.border = '0'
				img.onclick = btp.Mp3.makeToggle(img, o.href)
				o.parentNode.insertBefore(img, o)
		}
	}
},
	toggle: function(img, url) 
	{
		if (btp.Mp3.playimg == img) btp.Mp3.destroy()
		else {
			if (btp.Mp3.playimg) btp.Mp3.destroy()
			var a = img.nextSibling, c=''
			if (document.defaultView && document.defaultView.getComputedStyle) c = document.defaultView.getComputedStyle(a,null).getPropertyValue('color')
			else if (a.currentStyle) c = a.currentStyle['color']
			c = c.replace(/^rgb|[ ()]/g, '')
			var hex = c.match(/^#?([a-f0-9]{6})$/), hexSm = c.match(/^#?([a-f0-9]{3})$/), rgb = c.match(/^([0-9]+),([0-9]+),([0-9]+)$/)
			if (rgb) { var c16 = "0123456789abcdef", c=''; for(var i=1,d;d=rgb[i];i++) { var j=d%16; c=c+c16.charAt((d-j)/16)+c16.charAt(j) } }
			else if (hex) c = hex[1]
			else if (hexSm) c = hexSm[1].charAt(0) + hexSm[1].charAt(0) + hexSm[1].charAt(1) + hexSm[1].charAt(1) + hexSm[1].charAt(2) + hexSm[1].charAt(2)
			else c = "000000"
			img.src = Vanilla.webRoot+'extensions/Dplayer/on.gif'; 
			img.title = ''; 
			btp.Mp3.playimg = img;
			btp.Mp3.player = document.createElement('span')
			btp.Mp3.player.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
			'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
			'width="0" height="0" id="player" align="bottom">' +
			'<param name="wmode" value="transparent" />' +
			'<param name="allowScriptAccess" value="sameDomain" />' +
			'<param name="flashVars" value="theLink='+url+'&amp;fontColor='+c+'" />' +
			'<param name="movie" value="'+Vanilla.webRoot+'extensions/Dplayer/player.swf" />' +
			'<embed src="'+Vanilla.webRoot+'extensions/Dplayer/player.swf" flashVars="theLink='+url+'&amp;fontColor='+c+'"'+
			'wmode="transparent" width="0" height="0" name="player"' +
			'align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"' +
			' pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'
			img.parentNode.appendChild(btp.Mp3.player, img.nextSibling)
	}},
	destroy: function() {
		btp.Mp3.playimg.src = Vanilla.webRoot+'extensions/Dplayer/off.gif'; btp.Mp3.playimg = null
		btp.Mp3.player.removeChild(btp.Mp3.player.firstChild); btp.Mp3.player.parentNode.removeChild(btp.Mp3.player); btp.Mp3.player = null
	},
	makeToggle: function(img, url) { return function(){ btp.Mp3.toggle(img, url) }}
}

btp.addLoadEvent = function(f) { var old = window.onload
	if (typeof old != 'function') window.onload = f
	else { window.onload = function() { old(); f() }}
}

btp.addLoadEvent(btp.Mp3.go)
