// This file is used for interpreting MP3 or WMA files on Tag A.
// Powered by darin and you can visit my website for more: http://www.dARINMe.Net
// Keep these Three lines and you're free to use this code.

if(typeof(Darin) == 'undefined') Darin = {}
Darin.Audio = {
	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|wma$/i)) {
				var img = document.createElement('img')
				img.src = 'content/plugins/audio_label/images/play.gif'; img.title = 'listen'
				img.height = img.width = 16
				img.style.border = 'none'
				img.style.marginRight = '4px'
                img.style.marginTop = '5px'
                img.style.marginBottom = '-3px'
				img.style.cursor = 'pointer'
				img.onclick = Darin.Audio.makeToggle(img, o.href)
                o.href = 'http://www.dARINMe.Net'
                o.title = 'Audio File'
                o.innerHTML = 'Audio File: '+ o.innerHTML
				o.parentNode.insertBefore(img, o)
	}}},
	toggle: function(img, url) {
		if (Darin.Audio.playimg == img) Darin.Audio.destroy()
		else {
			if (Darin.Audio.playimg) Darin.Audio.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 = 'content/plugins/audio_label/images/close.gif'; Darin.Audio.playimg = img;
			Darin.Audio.player = document.createElement('div')
			Darin.Audio.player.innerHTML =
            '<div style="height:6px;overflow:hidden;filter:Alpha(opacity=25);"></div><object id="Exobud" codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" type="application/x-oleobject" height="69" standby="Loading Microsoft Windows Media Player components..." width="280" style="filter:Alpha(style=0); " classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">'+
                             ' <param name="AutoRewind" value="1">'+
                             ' <param name="FileName" value= "'+url+'">'+
                             ' <param name="ShowControls" value="1">'+
                             ' <param name="loop" value="1">'+
                             ' <param name="ShowPositionControls" value="1">'+
                             ' <param name="ShowAudioControls" value="1">'+
                             ' <param name="ShowTracker" value="1">'+
                             ' <param name="ShowDisplay" value="0">'+
                             ' <param name="ShowStatusBar" value="1">'+
                             ' <param name="ShowGotoBar" value="0">'+
                             ' <param name="ShowCaptioning" value="0">'+
                             ' <param name="AutoStart" value="1">'+
                             ' <param name="Volume" value="-1">'+
                             ' <param name="AnimationAtStart" value="0">'+
                             ' <param name="TransparentAtStart" value="0">'+
                             ' <param name="AllowChangeDisplaySize" value="0">'+
                             ' <param name="AllowScan" value="0">'+
                             ' <param name="EnableContextMenu" value="0">'+
                             ' <param name="ClickToPlay" value="0"></object>'
            img.parentNode.insertBefore(Darin.Audio.player, img.nextSibling)
	}},
	destroy: function() {
		Darin.Audio.playimg.src = 'content/plugins/audio_label/images/play.gif'; Darin.Audio.playimg = null
		Darin.Audio.player.removeChild(Darin.Audio.player.firstChild); Darin.Audio.player.parentNode.removeChild(Darin.Audio.player); Darin.Audio.player = null
	},
	makeToggle: function(img, url) { return function(){ Darin.Audio.toggle(img, url) }}
}

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

Darin.addLoadEvent(Darin.Audio.go)
