$(document).ready( function(){
	$("#container img").each(function(i){
		$(this).css( {'opacity':'0'} )
		$(this).attr( "src-bk", $(this).attr("src") );
		$(this).attr( "src", "" );
		$(this).load( function(){
			$(this).animate( {'opacity':'1'}, 250 );
			startLoad( $(this).next() );
			placeImages();
		} );
	});
	
	startLoad( $("#container img:first") );
	placeImages();
	fixContainerPos();
	
	$('.info li').mouseenter(function(){
		$(this).children('.drop').stop().animate( {'height':$(window).height()-100+'px','padding-top':'25px'}, 250 );
		$(this).attr( 'down', 'true' );
	}).mouseleave(function(){
		$(this).children('.drop').stop().animate( {'height':'0px','padding-top':'0'}, 200 );
		$(this).attr( 'down', 'false' );
	}).attr( 'down', 'false' );
	
	$('.info li .infolink').click( function(event){
		event.preventDefault();
	});
	
	$('.info li').click( function(){
		if ( $(this).attr('down') == 'false' ) {
			$(this).children('.drop').stop().animate( {'height':$(window).height()-100+'px','padding-top':'25px'}, 250 );
			$(this).attr( 'down', 'true' );
		} else {
			$(this).children('.drop').stop().animate( {'height':'0px','padding-top':'0'}, 200 );
			$(this).attr( 'down', 'false' );
		}
	} );
	
	$(window).resize( function(){
		fixContainerPos();
	});
	
	$('.info .about .drop').load( 'about.php' );
	$('.info .projects .drop').load( 'projects.php' );
		
} );

function startLoad( image ) {
	image.attr( "src", image.attr("src-bk") );
}

function placeImages(){
	var galleryWidth = 0;	
	$('#container img').each( function(){
		galleryWidth += $(this).innerWidth() + 20;
	} );	
	$('#container').css( {"width":galleryWidth+"px"} );	
}


function fixContainerPos(){
	
	var windowHeight = $(window).height();
	var pos = (windowHeight*0.4) - 225;
	if ( pos < 70 ) pos = 70;
	$('#container').css( {'top':pos+'px'} );
	
}