(function($) {
	var currentPlayer = null;

	function openPlayer(e) {
		if (currentPlayer) closePlayer();
		e.preventDefault();
		$(this).fadeOut('fast');
		var p = this;
		$(this).parent().animate({ width:'+=60px' }, 500, function() {
			var part = $(p).siblings('a').each(function() { var h = this.href; $(this).siblings('a').each(function() { this.href = h; }); });
			var href = p.href.slice(p.href.lastIndexOf('/')+1);
			currentPlayer = $('<div class="podcast-player"></div>').insertBefore(p).flash({
				src: '/flash/podcast-player.swf',
				width: 150,
				height: 16,
				wmode:'transparent',
				flashvars: { filename:href }
			});
		});
	}
	
	$.fn.closePlayer = function() {
		var p = currentPlayer.parent();	
		currentPlayer.remove();
		currentPlayer = null;
		$(p).stop().animate({ width:'-=60px' }, 400, function() { $(this).find('a').fadeIn('fast'); });
	}
	
	$(document).ready(function() {
		$('.podcast-info h3').css({ width:'240px' });
		$('<a class="listen-now" href="#">Listen Now</a>').css({ borderLeft:'solid 1px #8F856B', marginLeft:'5px' }).click(openPlayer).appendTo('.podcast-download');
	});
})(jQuery);

var closePlayer = $.fn.closePlayer;