$(document).ready(function(){
	
	page_height = $('#wrapper').height();
	var esc = '';
	var vidId = '';
	
	$(".vid").click(function(){
		var swf = this.href;
		vidId = "#"+this.id;
		esc = "vid";
		$('#screen_wrapper').ScrollTo(600, 'easeout');
		$('#screen').slideDown(1000,function(){
			$('#overlay').height(page_height);
			$('#overlay').show();
		  	$('#flash').flash(
				{
					src: swf,
					scale: 'noscale',
					width: 600,
					height: 480,
					allowScriptAccess: 'sameDomain'
				}
			);
			$('#close_btn').show();
			$(".close_vid").attr("id",vidId);
		});
		return false;
	});
	
	$(".close_vid").click(function(){
		var anchor = this.id;
		closeVid(anchor);
		return false;
	});
	
	function closeVid(anc){
		$('#flash').empty();
		$('#close_btn').hide();
		$('#screen').slideUp(1000,function(){
			$('#overlay').hide();
			$(anc).ScrollTo(600, 'easeout');
		});
		
	};
	
	$(".pic").click(function(){
		var caption = this.title
		var url = this.href;
		esc = "pic";
		$('#overlay').height(page_height);
		$('#overlay').show();
		$('#lg_pic_window').show(); 
		$("#lg_pic").attr("src",url); 
		$("#lg_pic").attr("alt",caption); 
		return false;	
	});
	
	$(".close_pic").click(function(){
		closePic();
		return false;
	});
	
	jQuery(document).keypress(function(ev) {
		if (ev.which == 27) {
			if (esc == 'pic') {
				closePic();
			}
			if (esc == 'vid') {
				closeVid(vidId);
			}
		};
	});
	
	function closePic(){
		$('#lg_pic_window').hide();
		$('#overlay').hide();
	};
	
});