(function($){
	$.fn.overlay_video = function(opts) {
		
		opts = $.extend({
			overlay: '.overlayMask',
			fade_speed: 600
		},opts);
		
		return $(this).each(function(){
			$video_trigger = $(this).find('a img');
			$video_trigger.click(function(e){
				e.preventDefault();				
				//fade in the overlay
				$overlay = $(opts.overlay);
				$overlay.fadeIn(opts.fade_speed);
				
				//load the video into the overlay
				$video_container = $overlay.find('.jvsOverlayVideo');
				$video_container.load('/media/video/'+$(this).attr('id')+'/#');
				//bind close function to overlay close button
				$($overlay.find('.overlayClose')).click(function(e){
					$video_container.empty();
					$overlay.fadeOut(opts.fade_speed);
					return false;
				});
				
			});
		});
	}
	
})(jQuery);
