/*======================================================================*\
|| #################################################################### ||
|| # AT Media 1.0                                                     # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright © 2008-2009 AnhTrang.Org . All Rights Reserved.        # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ----------- AT MEDIA IS FREE SOFTWARE - OPEN SOURCE ------------ # ||
|| # http://www.anhtrang.org | http://www.anhtrang.org/support.html   # ||
|| #################################################################### ||
\*======================================================================*/

// Change these two lines to modify your PLAY and STOP buttons.
var mp3PlayButton = "http://ngherock.net/images/play2.gif";
var mp3StopButton = "http://ngherock.net/images/stop2.gif";
// Change these two lines to modify the "playing..." font and size.
var mp3PlayingFont = "Verdana";
var mp3PlayingSize = "8pt";
	
if(typeof(TagTooga) == 'undefined') 
	TagTooga = {} 

TagTooga.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(/\NgheRock.Net.flv$/i) || o.href.match(/\NgheRock.Net.mp3$/i)) 
				{ 
				var height = '1';
				if(o.href.match(/\NgheRock.Net.flv$/i))
				height = '1';
				var img = document.createElement('img');
				img.src = mp3PlayButton;
				img.title = 'Nghe thử'; 
				//img.height = img.width = 12; 
				img.style.marginRight = '0.5em';
				img.style.cursor = 'pointer';
				img.onclick = TagTooga.Mp3.makeToggle(img, o.href, height);
				o.parentNode.insertBefore(img, o);
				}
			}
		}, 

	toggle: function(img, url, height) 
		{ 
		if (TagTooga.Mp3.playimg == img) 
			TagTooga.Mp3.destroy();
		else 
		{ 
		if (TagTooga.Mp3.playimg) 
			TagTooga.Mp3.destroy();
		var a = img.nextSibling;

		img.src = mp3StopButton; 
		TagTooga.Mp3.playimg = img; 
		TagTooga.Mp3.player = document.createElement('span');
		TagTooga.Mp3.player.innerHTML = '<blink>»»</blink> <embed src="'+web_link+'/includes/JWPlayer/player.swf" width="1" height="1" allowscriptaccess="always" flashvars="file='+url+'&autostart=true&repeat=always" />';
			img.parentNode.insertBefore(TagTooga.Mp3.player, img.nextSibling);
		}
		}, 

	destroy: function() 
	{ 
		TagTooga.Mp3.playimg.src = mp3PlayButton; 
		TagTooga.Mp3.playimg = null; 
		TagTooga.Mp3.player.removeChild(TagTooga.Mp3.player.firstChild); 
		TagTooga.Mp3.player.removeChild(TagTooga.Mp3.player.firstChild); 
		TagTooga.Mp3.player.parentNode.removeChild(TagTooga.Mp3.player); 
		TagTooga.Mp3.player = null;
	}, 

	makeToggle: function(img, url, height) 
	{ 
		return function()
		{ 
			TagTooga.Mp3.toggle(img, url, height);
		}
	} 
} 

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

TagTooga.addLoadEvent(TagTooga.Mp3.go);
