jQuery(function($) {
	$('#audio-player-widget').jPlayer({
		ready:function() {
			$(this).jPlayer("setMedia", {/*m4a:$(".audio-item:first .audio-content").attr('href'),*/ mp3:$(".audio-item:first .audio-content").attr('href')});
			$(this).jPlayer("play");
			$('#audio-title').html($('.audio-item:first .audio-title').clone());
		},
		swfPath:'./scripts',
		supplied:'mp3',
		solution:"flash, html",
		wmode:'transparent',
		size:{width:1,height:1},
		play:function() {
			$('#audio-play').hide();
			$('#audio-pause').show();
		},
		pause:function() {
			$('#audio-pause').hide();
			$('#audio-play').show();
		}
	});

	$('a.player').live('click', function() { // pause player when a new audio item launches
		$('#audio-player-widget').jPlayer('pause');
	});

	$('a.player-audio-link').live('click', function(e) {
		e.preventDefault();
		$('#audio-player-widget').jPlayer('setMedia', {mp3:$(this).attr('rel')});
		$('#audio-player-widget').jPlayer("play");
		$('#audio-title').html($("<a />", {target:"_blank", href:$(this).attr('href'), html:$(this).html()}));
	});

	$('a.player-video-link').live('click', function(e) {
		e.preventDefault();
		$('#audio-player-widget').jPlayer("pause");
		$.fancybox({
			type:'iframe',
			href:$(this).attr('href'),
			width:640,
			height:380,
			scrolling:'no'
		});
		/*
		$.ajax({
			url:"ajax/ajax_getVideoEmbed.php",
			data:{id:$(this).closest('ul').attr('id').match(/[0-9]+$/)[0],videoID:$(this).attr('id').match(/[0-9]+$/)[0]},
			type:'get',
			dataType:'json',
			success:function(res) {
				$('#audio-player-widget').jPlayer('pause');
				var embed = $(res.data);
				$.fancybox(embed);
			}
		});
		*/
		$(this).closest('li').find('.player-video-embed').fancybox();
	});

	$('#audio-play').click(function() {$('#audio-player-widget').jPlayer('play');});
	$('#audio-pause').click(function() {$('#audio-player-widget').jPlayer('pause');});
	
	function animLeft() {
		$('#audio-title a').stop().animate({'left':'-'+($('#audio-title a').width()-$('#audio-title').width())+"px"}, 3000, 'linear');
	}

	function animRight() {
		$('#audio-title a').stop().animate({'left':0}, 3000, 'linear');
	}

	setTimeout(function() {setInterval(animLeft, 8000)}, 2000);
	setTimeout(function() {setInterval(animRight, 8000)}, 6000);
});

