// JavaScript Document

//---------------------------------------------------------------------
// AUDIO PLAYER FUNCTIONS
//---------------------------------------------------------------------
var webroot;
$(document).ready(function(){
	if($('#content a.audio_player').length > 0){
		init_player();
		$('#content a.audio_player').each(function(i,elem){
			var href = $(elem).attr('href');
			href = href.replace('http://'+webroot, '');
			if(href.search(/(\/resources\/songs\/)([0-9]+)(\-)/g) != -1){
				href = href.replace('/resources/songs/','');
				href = href.replace('/','');
				var tmp = href.split('-');
				var songid = tmp[0];
				if(parseInt(songid) != 0){
					// catch for non-flash users
					//$(elem).attr('href','#');
					//$(elem).attr('title','Flash is required to listen to this song!');
					
					var url = '/song-mp3.php?id='+songid;
					var info = $(elem).text().split('-');
					var title = (info[0] != null && info[0] != '') ? info[0].trim() : '';
					var artist = (info[1] != null && info[1] != '') ? info[1].trim() : '';
					$(elem).attr('id','audio_player'+i);
					load_file('audio_player'+i, url, 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: '212121',
			leftbg: '0E0E0E',
			lefticon: '8FD0E0',
			voltrack: '666666',
			volslider: '8FD0E0',
			rightbg: '0E0E0E',
			rightbghover: '0E0E0E',
			righticon: '8FD0E0',
			righticonhover: 'FFFFFF',
			loader: '8FD0E0',
			track: '212121',
			tracker: '666666',
			border: '212121',
			text: 'FFFFFF'
		});
	}
}

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