var freezeScroll;
var projectTitle;

$(function() {

	$('.email').mailto();
	
});

function toggleProjectDescription(state) {
	
	/* Show */
	if(state) {
	
		$("#project-header-wrapper").show();
		$("#project-images").offset({top: $("#project-images").offset().top - $("#header").outerHeight()+1});
	
		fadeInAndOut("#tagline", projectTitle);
		
		$('#tagline:first-child').unbind('click');
		
		freezeScroll = true;
		
		$('html, body').animate({scrollTop:0}, 'fast', function() {
			freezeScroll = false;
		});		
	}
	
	/* Hide */
	else {
		$("#project-header-wrapper").hide();
		
		// Change tagline to "Show Description"
		projectTitle = $("#tagline").text();
		fadeInAndOut("#tagline", '<span style="cursor: pointer; width: auto"><span style="font-size: 20px">&#9617;</span> Show Project Description</span>');
		
		// Set proper position for continued Image scrolling
		$("#project-images").offset({top: $("#header").outerHeight()+1});
		$("html, body").scrollTop(0);
				
		// Add clickable Tagline ("Show description")
		$("#tagline:first-child").click(function() {
				
			toggleProjectDescription(true);
										
		});
	}
}

function fadeInAndOut(element, html) {

	$(element).fadeTo( 300, 0, function() {
		
		$(element).html(html);
		$(element).fadeTo( 300, 100 );
	});
}

function isHeaderOutside() {
	
	var response;
	
	if( $("#project-header-wrapper").is(":visible") ) {
	
		var elementHeight = $("#project-header-wrapper").outerHeight();
		var scrollPosition = $(window).scrollTop();
		var headerHeight = $("#header").outerHeight();
	
		response = (scrollPosition >= ( elementHeight - headerHeight ));
	}
	else { response = false; }
	
	return response;
}

