
//functions used by Flash video player
var expandVideo = function(contId) {
	$('#' + contId).animate({
		width: '636px',
		height: '477px'
	});
};
var contractVideo = function(contId) {
	$('#' + contId).animate({
		width: '320px',
		height: '240px'
	});
};


$(function() {
	
	//no need to go further without Flash
	if(!CitiUtil.hasFlash()) { return; }

	var audio_swf = CitiUtil.getFilesPath() + 'flash/audio_player.swf',
		video_swf = CitiUtil.getFilesPath() + 'flash/video_player.swf';
	
	$('a.play-audio').click(function() {
		var $this = $(this).css('overflow','hidden'),
			aud = $this.attr('href'),
			$container = $('<div class="audio-player-container" />'),
			id = 'audio-' + Math.floor(Math.random()*100000);
		//add audio container
		$container.attr('id',id).insertBefore($this);
		
		var flashVars = {};
			flashVars.audioPath = aud;
			flashVars.autoPlay = 'true';
		CitiUtil.embedFlash(id,audio_swf,387,48,flashVars);

		//animate listen link off screen		
		$this
			.animate({
				marginLeft: '-200px',
				opacity: 0
			},{
				duration: 250,
				complete: function() {
					$this.hide();
				}
			});
		//animate audio player in (delayed slightly)	
		setTimeout(function() {
			$container
				.animate({
					marginLeft: '0'
				}, 250);
		},100);
		return false;		
	});

	$('a.view-video')
		.each(function() {			
			var $this = $(this),
				vid = $this.attr('href').replace('.m4v','.flv'),
				pos = $this.find('img').attr('src'),
				$container = $('<div class="video-player-container" />'),
				id = 'video-' + Math.floor(Math.random()*100000);
			//check heights
			var quoteH = $this.siblings('.video-content').height();
			if(quoteH > $this.height()) {
				$this.parents('.video-player').height(quoteH)
			}
			$container.attr('id',id).insertBefore($this);
			$this.hide();
			var flashVars = {};
				flashVars.videoPath = vid;
				flashVars.posterPath = pos;
				flashVars.videoId = id;
			CitiUtil.embedFlash(id,video_swf,636,477,flashVars);
		});
});

