// JavaScript Document

//---------------------------------------------------------------------
// AUDIO PLAYER FUNCTIONS
//---------------------------------------------------------------------
$(document).ready(function(){
	if($('#text a.audio_player').length > 0){
		init_player();
		$('#text a.audio_player').each(function(i,elem){
			var mp3 = $(elem).attr('href');
			if(mp3 != null && mp3.substring(mp3.length - 3) == 'mp3'){
				// catch for non-flash users
				$(elem).attr('href','#');
				$(elem).attr('title','Flash is required to listen to this MP3 file!');
				
				var info = $(elem).text().split('-');
				var title = (info[0] != null && info[0] != '') ? info[0].trim() : '';
				title = title.replace(',',' ');
				var artist = (info[1] != null && info[1] != '') ? info[1].trim() : '';
				artist = artist.replace(',',' ');
				$(elem).attr('id','audio_player'+i);
				load_file('audio_player'+i, mp3, title, artist);
			}
		});
	}
});

function init_player(){
	if(typeof(AudioPlayer) != null){
		AudioPlayer.setup("/scripts/AudioPlayer/audio-player.swf", {
			width: 400,
			transparentpagebg: 'yes',
			animation: 'no',
			initialvolume: '80',
			bg: '999999',
			leftbg: 'CA2027',
			lefticon: 'FFFFFF',
			voltrack: '464646',
			volslider: 'FFFFFF',
			rightbg: 'CA2027',
			rightbghover: '464646',
			righticon: 'FFFFFF',
			righticonhover: 'FFFFFF',
			loader: 'CA2027',
			track: 'FFFFFF',
			tracker: 'D3D3D3',
			border: 'CCCCCC',
			text: '333333'
		});
	}
}

function load_file(selector, file, title, artist){
	if(typeof(AudioPlayer) != null){
		AudioPlayer.embed(selector, {
			soundFile: file,
			titles: title,
			artists: artist
		});
	}
}