$(document).ready(function () {
	loaddocs();
	navfade();
});
$(window).load(function () {
 	logodrop();
});

//functions
function loaddocs() {
	$(".documents li").click(function() {
		var document = $(this).attr("class");

		$("#control-panel").animate({top:-78},500);
		$("#footer").fadeOut(500);
		$(".burrito").fadeOut(500);
		$("#retorq").fadeOut(500);
		$("body").addClass("document-viewer");
		
		setTimeout( function() {
			$("#document-viewer").load("documents.php #" + document).show();
		}, 600);
		closedocs();
	});
}
function closedocs() {
	$("#close-button").click(function() {
		$(this).css("top", "22px"); //simulate button press (up and down)
		setTimeout( function() {
			$("#close-button").css("top", "20px");
		}, 100);
		
		$("#control-panel").animate({top:0},500);
		$("#document-viewer").fadeOut(500);
		setTimeout( function() {
			$("body").removeClass("document-viewer");
			$("#document-viewer div").remove();
			$(".burrito").fadeIn();
			$("#footer").fadeIn();
			$("#retorq").fadeIn();
		}, 600);
	});
	
	$(document).keyup(function(e){
		if (e.keyCode == 27) { //escape
			$("#close-button").css("top", "22px");
			setTimeout( function() {
				$("#close-button").css("top", "20px");
			}, 100);
			
			$("#control-panel").animate({top:0},500);
			$("#document-viewer").fadeOut(500);
			setTimeout( function() {
				$("body").removeClass("document-viewer");
				$("#document-viewer div").remove();
				$(".burrito").fadeIn();
				$("#footer").fadeIn();
				$("#retorq").fadeIn();
			}, 600);
		}
	});
}


function logodrop() {
	$("#logo").animate({top:'4px'}, 1250 ).animate({top:'0px'}, 200);
}

function navfade() {
	$("#control-panel ul li a").hover(
		function() {
			$("#control-panel ul li").children("a").addClass("other-links");
			$(this).removeClass("other-links");
			$(".other-links").stop().animate({"opacity":"0.5"},200);
		},
		function() {
			var hoveredlink = $(this);
			$(".other-links").animate({"opacity":"1"},500);
			$("#control-panel ul li").children("a").removeClass("other-links");
			//$("#control-panel ul li a").animate({"opacity": "1"}, 200);
			//$(hoveredlink).removeClass("hovered");
		}
	);
}




$(function() {
	var htmlheight = $("html").height();
	$(".overlay").css("height", htmlheight+"px");
});
	
$(function() {
    $("* h6 img").click(    
    
    function() {
    	$(".overlay").fadeIn();
    	
    	var lbi = "#" + $(this).parent().attr('class'); //lightbox image (lbi)
    	$(lbi).show();
    	
    	var calcHeight = ((($(window).height() - $(lbi).height())/2)+$(window).scrollTop());
    	$(lbi).css('top', calcHeight + 'px');   	
    }
	); 
});

$(function() { 
     $(".quit").click(
     	function() { 
     		$(".overlay").fadeOut(); 
     		$(".overlay div").hide();
     	}
     ); 
});

