$(function(){
	
	var contentShown = false;
	var currentContent;
	var animating = false;
	
	function refreshCode() {
		$('#current a').click(function(evt){
			if(animating == false){
				animating = true;
				if(contentShown == true){
					$('#projectContent').slideUp(1000, function(){
						$('#projectContent').remove();
						var content = "content.html #";
						var tempContent = evt.currentTarget.id;
						currentContent = evt.currentTarget.id;
						content += tempContent;
						content += "Full";
						$('<div id ="projectContent" />').load(content, function() {
							$(this).appendTo('#info-inside').hide().slideDown(1500, function(){
								animating = false;
								console.log("animating = " + animating);
							}); 
						});
					});
				} else {
					console.log("boom");
					contentShown = true;
					var content = "content.html #";
					var tempContent = evt.currentTarget.id;
					currentContent = evt.currentTarget.id;
					content += tempContent;
					content += "Full";
					$('<div id ="projectContent" />').load(content, function() {
						$(this).appendTo('#info-inside').hide().slideDown(1500, function(){
							animating = false;
							console.log("animating = " + animating);
						}); 
					});
				}
			}
		});
		
		$('#current a').hover(function(evt){
			var content = "content.html #" + this.id + "Snippet";
			console.log(content);
			$('<div id ="snippet" />').load(content, function() {
				$(this).appendTo('body');
				$('#snippet')
					.css('top', evt.pageY-20)
					.css('left', evt.pageX+40)
					.hide()
					.fadeIn(400);
			});
		}, function(){
			$('#snippet').fadeOut(200).remove();
		});
		
		$('#current a').mousemove(function(evt){
			$('#snippet')
				.css('top', evt.pageY-20)
				.css('left', evt.pageX+40);
		});
		
		$('#previous a').hover(function(evt){
			var content = "content.html #" + this.id + "Snippet";
			console.log(content);
			$('<div id ="snippet" />').load(content, function() {
				$(this).appendTo('body');
				$('#snippet')
					.css('top', evt.pageY-20)
					.css('left', evt.pageX+40)
					.hide()
					.fadeIn(400);
			});
		}, function(){
			$('#snippet').fadeOut(200).remove();
		});
		
		$('#previous a').mousemove(function(evt){
			$('#snippet')
				.css('top', evt.pageY-20)
				.css('left', evt.pageX+40);
		});
		
		$('#previous a').click(function(evt){
			if(animating == false){
				animating = true;
				if(contentShown == true){
					$('#projectContent').slideUp(1000, function(){
						$('#projectContent').remove();
						var content = "content.html #";
						var tempContent = evt.currentTarget.id;
						currentContent = evt.currentTarget.id;
						content += tempContent;
						content += "Full";
						$('<div id ="projectContent" />').load(content, function() {
							$(this).appendTo('#info-inside').hide().slideDown(1500, function(){
								animating = false;
								console.log("animating = " + animating);
							}); 
						});
					});
				} else {
					console.log("boom");
					contentShown = true;
					var content = "content.html #";
					var tempContent = evt.currentTarget.id;
					currentContent = evt.currentTarget.id;
					content += tempContent;
					content += "Full";
					$('<div id ="projectContent" />').load(content, function() {
						$(this).appendTo('#info-inside').hide().slideDown(1500, function(){
							animating = false;
							console.log("animating = " + animating);
						}); 
					});
				}
			}
		});
	}
	
	$('<div id ="info-inside" />').load('content.html #home', function() {
		$(this).appendTo('#content').hide().slideDown(1500); 
	});
	
	
	
	$('#navbar a').click(function(evt){ //needs to be modified to detect if a project in current/previous projects is being shown,
		if(animating == false){
			animating = true;
			if(contentShown == true){
				contentShown = false;
				var projectContent = "#" + currentContent + "Full";
				console.log(projectContent);
				$(projectContent).slideUp(1000, function(){
					console.log(projectContent);
					$(projectContent).remove();
					$('#info-inside').slideUp(1000, function(){
						$('#info-inside').remove();
						var content = "content.html #";
						var tempContent = evt.currentTarget.id;
						content += tempContent;
						$('<div id ="info-inside" />').load(content, function() {
							$(this).appendTo('#content').hide().slideDown(1500, function(){
								refreshCode();
								animating = false;
								console.log("animating = " + animating);
							}); 
						});
					});
				});
			} else {
				$('#info-inside').slideUp(1000, function(){ //if so first slide up and remove said project and then the whole thing
					$('#info-inside').remove();
					var content = "content.html #";
					var tempContent = evt.currentTarget.id;
					content += tempContent;
					$('<div id ="info-inside" />').load(content, function() {
						$(this).appendTo('#content').hide().slideDown(1500, function(){
							refreshCode();
							animating = false;
							console.log("animating = " + animating);
						}); 
					});
				});
			}
		}
	});
	
	$('#navbar img').hover(function() {
    	$(this).attr("src", $(this).attr("src").split("1").join("2"));
  	}, 
  	function() {
  		$(this).attr("src", $(this).attr("src").split("2").join("1"));
  	});

});
