/* based on del.icio.us playtagger */
if(typeof(CF) == 'undefined') CF = {}
CF.Mp3 = {
	playimg: null,
	player: null,
        currentpath: null,
	toggle: function(img, url, path) {
	        CF.Mp3.currentpath = path;
		if (CF.Mp3.playimg == img) CF.Mp3.destroy()
		else {
			if (CF.Mp3.playimg) CF.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 = path + 'stop.gif'; CF.Mp3.playimg = img;
			CF.Mp3.player = document.createElement('span')
			CF.Mp3.player.innerHTML = '<object style="vertical-align:bottom;margin-right:0.2em" 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="middle">' +
			'<param name="wmode" value="transparent" />' +
			'<param name="allowScriptAccess" value="sameDomain" />' +
			'<param name="flashVars" value="theLink='+url+'&amp;fontColor='+c+'" />' +
			'<param name="movie" value="' + path + 'playtagger.swf" /><param name="quality" value="high" />' +
			'<embed style="vertical-align:bottom;margin-right:0.2em" src="'+path+'playtagger.swf" flashVars="theLink='+url+'&amp;fontColor='+c+'"'+
			'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" /></object>'
			img.parentNode.insertBefore(CF.Mp3.player, img.nextSibling)
	}},
	destroy: function() {
		CF.Mp3.playimg.src = CF.Mp3.currentpath + 'play.gif'; CF.Mp3.playimg = null
		CF.Mp3.player.removeChild(CF.Mp3.player.firstChild); CF.Mp3.player.parentNode.removeChild(CF.Mp3.player); CF.Mp3.player = null
	}
}


