$(document).ready(function() {
	
	
	$('ul.popupThumbs li').mouseover(function() {
		var position = $(this).position();
		//var thumbOverContent = $(this).parent().find('.thumbOverContent').html();
		$(this).find('.thumbOver').show();
		return false;
	});
	
	$('.thumbOver').mouseleave(function() {
		$('.thumbOver').hide();
		return false;
	});
	/*
	$('.thumbOver').each(function() {
		$this = $(this);
		$thisContent = $this.find('div');
		
		var thisHeight = $this.outerHeight();
		var contentHeight = $thisContent.outerHeight();
		alert(thisHeight);alert(contentHeight);return;
		var paddingTop = (thisHeight-contentHeight)/2;
		$thisContent.css({'padding-top':paddingTop});
	});
	*/
	
	$('.thumbOver a.popupLink').click(function() {
		if($(this).attr('href') == '#')
		{
			var $next = $(this).parents('.thumbOver').next('.popupContent');
			if($next.length != 0)
			{
				var popupContent = $($next).html();
				$('#popup .popupContent').html(popupContent);
				
				$('#popupFade').show().height($(document).height());
				$('#popup').css({ 'top':($(window).height()/2 - $('#popup').height()/2)+$(window).scrollTop() }).fadeIn('fast');
			}
			return false;
		}
	});
	
	$('#popupFade, #popup a.closeButton').click(function () {
		hidePopup();
		return false;
	});
	
	$(document).keypress(function (e) {
		if (e.keyCode == 27) {
			hidePopup();
			return false;
		}
	});
	
	function hidePopup() {
		$('#popup').fadeOut('fast',function () {
			$('#popupFade').hide();
		}).find('popupContent').html('&nbsp;');
	}

});
