var APlay;
if (!APlay)
{
	APlay = {};
	
	APlay.player_layer_id = 'player_audio';
	
	APlay.play = function(id, file)
	{
		if (document.getElementById(APlay.player_layer_id) && document.getElementById('audio_'+id))
		{
			var title_start = 'Играть';
			var title_stop = 'Остановить';
			if (document.getElementById('audio_'+id).src.match(/\/i\/audio_played\.gif/))
			{
				document.getElementById(APlay.player_layer_id).innerHTML = '';
				document.getElementById('audio_'+id).src='/i/audio_play.gif';
				document.getElementById('audio_'+id).alt=title_start;
				document.getElementById('audio_'+id).title=title_start;
			}
			else
			{
				for (var key in document.images)
				{
					if (document.images[key].id && document.images[key].id.indexOf('audio_') == 0)
					{
						if (document.images[key].src.match(/\/i\/audio_played\.gif/))
						{
							document.images[key].src = '/i/audio_play.gif';
							document.getElementById('audio_'+id).alt=title_start;
							document.getElementById('audio_'+id).title=title_start;
						}
		
					}
				}
				document.getElementById('audio_'+id).src='/i/audio_played.gif';
				document.getElementById('audio_'+id).alt=title_stop;
				document.getElementById('audio_'+id).title=title_stop;
				document.getElementById(APlay.player_layer_id).innerHTML = '';
				var player_str = '<object type="application/x-shockwave-flash" data="/users/musicplayer.swf?autoplay=true&song_url='+file+'" width="1" height="1"><param name="movie" value="/users/musicplayer.swf?autoplay=true&song_url='+file+'" /></object>';
				document.getElementById(APlay.player_layer_id).innerHTML = player_str;
			}
		}
	}
	
	APlay.init = function()
	{
		if (!document.getElementById(APlay.player_layer_id))
		{
			var layer = document.createElement('div');
			layer.id = APlay.player_layer_id;
			//layer.style.position = 'absolute';
			//layer.style.width = '1px';
			//layer.style.height = '1px';
			document.body.appendChild(layer);
			var layer = document.getElementById(APlay.player_layer_id);
			layer.style.width = '1px';
			layer.style.height = '1px';
			layer.style.position = 'absolute';
			//document.body.appendChild(document.createElement('div'));
			//alert(document.body.innerHTML);
			
		}
	}
	
	if (window.addEventListener)
	{
		window.addEventListener("load", APlay.init, false);
	}
	else if (window.attachEvent)
	{
		window.attachEvent("onload", APlay.init);
	}
	else
	{
		window.onload = APlay.init;
	}
}
