// WHOA, NELLY!!
// I am by no means a jQuery expert, and therefor this jQuery code is not the most effecient there is.
// But it works. So I'm happy.
// Don't judge me.




$(window).load(function() {





//--------------------------------------------------------------------------------------------
//POSITION DATE, NAME AND GRAPHIC FLOATING ELEMENTS
//--------------------------------------------------------------------------------------------

var siteleft = $('body').width() - $('#content').width();
siteleft = siteleft/2;


$('.name').css('left', siteleft - 493);

$('.graphic').css('right', siteleft - 475);


//--------------------------------------------------------------------------------------------
//RE-POSITION STRINGS AND FLOATING ELEMENTS ON WINDOW RESIZE
//--------------------------------------------------------------------------------------------

$(window).resize(function() {
	
	siteheight = $('#container').height();
    
	
	siteleft = $('body').width() - $('#content').width();
	siteleft = siteleft/2;
	
	$('.name').css('left', siteleft - 493);
	$('.graphic').css('right', siteleft - 475);
	$('.xleft').css('left', siteleft - 256);
	$('.xright').css('right', siteleft - 475);
	
	
    
});

//--------------------------------------------------------------------------------------------
//DEFINE FUNCTIONS
//--------------------------------------------------------------------------------------------
function isScrolledIntoView(elem) {
 var docViewTop = $(window).scrollTop() +136;
 var docViewBottom = $(window).scrollTop() + 137;

 var elemTop = $(elem).offset().top;
 var elemBottom = elemTop + $(elem).height();

 return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
}



//--------------------------------------------------------------------------------------------
// SHOW / HIDE DATE & GRAPHICS AS YOU SCROLL THROUGH THE DIFFERENT SECTIONS
//--------------------------------------------------------------------------------------------

/*$('#post-1').addClass('nextpost');
*/
$(window).scroll(function() {
   		
/*   		if(isScrolledIntoView('#post-1') || isScrolledIntoView('#header')) { 
        		
        		$('#post-1').addClass('nextpost');
				
        }*/
   
   		$('.section').each(function(){
   			
   			if(isScrolledIntoView(this)) { 
        		
        		$(this).children('.name, .graphic').fadeIn(100);
/*        		$('#post-1').removeClass('nextpost');
				$(this).prev('.post').addClass('prevpost');
				$(this).next('.post').addClass('nextpost');*/
				
        	} else {
        		$(this).children('.name, .graphic').fadeOut(100);
        		/*$(this).prev('.post').removeClass('prevpost');
				$(this).next('.post').removeClass('nextpost');*/
        	}
   			
   		});
   		
   		
   		    
});






});




