function embedVideo(targetId, videoPath) {
	flashembed(targetId, 
   
        /* 
            first argument supplies standard Flash parameters. See full list:
            http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701
        */
      {
         src: BASE + '/flowplayer/FlowPlayerDark.swf',
         width: 480, 
         height: 360
      },
        
      /*
            second argument is Flowplayer specific configuration. See full list:
            http://flowplayer.org/player/configuration.html
        */
      {config: {   
            videoFile: videoPath,
            autoPlay: false
      }} 
   );   
}

$(function() {
	if ($('#home-video').size() > 0) {
		embedVideo('home-video', BASE + '/videos/home.flv');
	}
	
	if ($('#work-player').size() > 0) {
		// Bind videos
		$('.video-thumbs a').click(function() {
			// Load video
			var el = $(this);
			var videoPath = el.attr('href');
            embedVideo('work-player', videoPath);
			
			// Load sidebar
			// Heading
			var heading = el.children('span').text();
			$('#player-sidebar h2').text(heading);
			
			var description = el.next('.video-description').clone();
			$('#video-desc').empty().append(description);
			
			return false;			   	
		}).hover(function() {
			// Show video title
			var el = $(this);
			var title = el.children('span').text();
			var offset = el.offset();
			title = $('<div id="video-title-hover">' + title + '</div>').css({
				position: 'absolute',
				top: offset.top - 24,
				left: offset.left + 80,
				opacity: 0.75
			});
			$('body').append(title);
		}, function() {
			$('#video-title-hover').remove();
		});
	}
	
	// Watch bio
	var watchBioEl = $('#watch-bio a');
	if (watchBioEl.size() > 0) {
		watchBioEl.click(function() {
			// Append BG
			var background = $('<div id="bio-background"></div>').css({
		        opacity: 0.4,
				position: 'absolute',
				top: 0,
				left: 0,
				width: '100%',
				height: '100%',
				background: '#000',
				zIndex: 20
		    });
		    $('body').append(background);
			
			var dialog = $('<div id="bio-dialog"><a id="close-dialog" href="#Close">Close</a><div id="bio-player"></div></div>')
			$('body').append(dialog);
			
			$('#close-dialog').click(function() {
				$('#bio-background, #bio-dialog').remove();
				return false;
			});
			
			var videoPath = watchBioEl.attr('href');
			embedVideo('bio-player', videoPath);
			
			return false;
		});
	}
	
	// Load the first video
	
	var el = $('#choose-video ul:first li:first a');
	if (el.size()) {
		var heading = el.children('span').text();
	    $('#player-sidebar h2').text(heading);

	    var description = el.next('.video-description').clone();
	    $('#video-desc').empty().append(description);

		var videoPath = el.attr('href');
	    embedVideo('work-player', videoPath);
	}

	
	// IE6 :hover fix
	// $.ie6CssFix();
});

