var $j = jQuery.noConflict();
$j.tmpMP3HTML = '';
$j.isPlaying = false;
$j.isPlayingPath = '';

function initMP3Player(){
	if(typeof(showMP3Player) == 'undefined' || showMP3Player == false){
		if($j('#mp3Container').html() != ''){
			$j.tmpMP3HTML = $j('#mp3Container').html();
		}
		if($j('#mp3Container').css('display') != 'none'){
			$j('#mp3Container').fadeOut('slow', function(){$j('#mp3Container').html('');});
		}
	}
	else{
		if($j('#mp3Container').css('display') != 'block'){
			if($j.tmpMP3HTML != ''){
				$j('#mp3Container').html($j.tmpMP3HTML);
			}
			$j('#mp3Container').fadeIn('slow');
		}
	}
	showMP3Player = false;
	setTimeout('doMp3Autoplay()', 1000);
}

$j(document).ready(function(){
	initMP3Player();
});

function doMp3Autoplay(){
	if($j('#mp3Container').css('display') != 'block'){
		$j.isPlaying = false;
		$j.isPlayingPath = '';
		return;
	}
	if($j.isPlaying == true){
		initNowPlaying();
		return;
	}
	if(typeof(autoPlayMp3) != 'undefined' && typeof(loadMp3) != 'undefined'){
		if($j.isPlayingPath != autoPlayMp3.path){
			loadMp3(autoPlayMp3.path, autoPlayMp3.title, autoPlayMp3.caption, autoPlayMp3.genre);
			$j.isPlaying = true;
			$j.isPlayingPath = autoPlayMp3.path;
		}
		if(typeof(resetIsPlaying) != 'undefined'){
			$j.isPlaying = false;
			$j.isPlayingPath = '';
		}
	}
	initNowPlaying();
}

function initNowPlaying(){
	$j('.play_track_link').each(function(){
								url = $j(this).attr('href');
								recID = $j(this).attr('id').split('_')[2];
								rowID = 'play_track_row_'+recID;
								if(typeof($j.isPlayingPath) != 'undefined' && $j.isPlayingPath == url+'/.mp3'){
									$j('#'+rowID).addClass('now_playing');
									return;
								}
							});
}
