(function($) {

	function fadeContent(){
		$('.cCont').fadeIn();
		$('div.fbLike').delay(1000).fadeIn();
	}

	function initGallery(){
		var bgHeight = $(document).height();
		var bgWidth = $(window).width();
		var winH = $(window).height();
		var winW = $(window).width();
		var scrollPos = $(window).scrollTop();

		$('#galBgLayer').css({'width':bgWidth,'height':bgHeight});
		$('#galBgLayer').fadeIn();

		$('div.galleryCont').css('left', winW/2-$('div.galleryCont').width()/2);
		$('div.galleryCont').css('top',  winH/2-$('div.galleryCont').height()/2 + scrollPos);
		$('div.galleryCont').fadeIn();

		$(window).resize(function() {
			$('#galBgLayer').css({'width':$(window).width(),'height':$(document).height()});
			$('div.galleryCont').css('left', $(window).width()/2-$('div.galleryCont').width()/2);
			$('div.galleryCont').css('top',  $(window).height()/2-$('div.galleryCont').height()/2 + $(window).scrollTop());
		});

		$(document).keypress(function(e) {
			if (e.keyCode == 27) {
				$('#galBgLayer').fadeOut();
				e.preventDefault();
			}
		});

		$(window).scroll(function(){
			scrollPos = $(window).scrollTop();
			$('div.galleryCont').css('top',  winH/2-$('div.galleryCont').height()/2 + scrollPos);
		});

		$('a.closeBtn').click(function(e){
			$('#galBgLayer').fadeOut();
			e.preventDefault();
		});

	}

$(function(){
	fadeContent();

	$('div.imgCont a').click(function(e){
		var imgSrc = $(this).attr('href');
		var imgTitle = $(this).find('img').attr('alt');
		var imgDesc = $(this).attr('rel');
		//$('img#galImg').attr('src',imgSrc);
		$('img#galImg').attr('alt',imgTitle);
		$('div.picCont').html("<img src=\""+imgSrc+"\" alt=\"\">");
		$('div.galleryFooter').html("<p><strong>"+imgTitle+"</strong><br />"+imgDesc+"</p>");
		initGallery();
		e.preventDefault();
	});


});

})(jQuery);

