var closer = false;

$( function() {

		$('#work-directors ul li a').click( function(e) {
				var target = $(e.target);

				target.blur();
				var videoURL = target.attr('href');
				var meta = target.attr('rel');
 				meta = meta.replace('|', '<br />');
 				meta = meta.replace('|', '<br />');


 				if ( $('#work-video').length == 0 ) {
 					$( '#work').prepend ( '<div id="work-video"></div>' );				
 				}

 				$('#work-directors').hide();

				var s = '';
				s += '<a href="/" id="work-video-close"><span>Close</span></a>';
				s += '<div id="work-video-player">';
				s += '<embed src="' + videoURL + '" width="512" height="384"></embed>';
				s += '<p>';
				s += meta;
				s += '</p>';
				s += '</div>';

				$('#work-video').html ( s );

				location.hash = 'video';
				closer = setInterval( checkBack, 100 ); 

				$('#work-video-close').click( function() {
					workVideoClose();
					return false;
				});

 				return false;

 			});

	});



function checkBack() {
	if ( location.hash != '#video' ) {
		workVideoClose();
	} 
}

function workVideoClose() {
	location.hash = '';
	clearInterval ( closer );
	$('#work-video').remove();
	$('#work-directors').show();
	return false;
}
