$(document).ready(function(){
	var currentLoc = "";
	var currentLabel = "";
	var currentHighlight = "";
	var currentText = "";
	var fadeNormal = .15;
	var fadeOver = .9;
	$(".page-image").fadeTo(1,0);
	$(".page-image").show();
	$(".page-image").fadeTo(500,1, function() {
	
	});
	tb_show(null, "#TB_inline?height=200&amp;width=300&amp;inlineId=instruction-text&amp;modal=true", null);
	
	
	$(".outer-label").hover(
		function() {
			currentLoc = $(".label",this).attr("id");
			currentHighlight = "#" + currentLoc + "-hilight";
			
			currentLabel = "#" + currentLoc + "-label";
			$(currentLabel).show();
			$(currentHighlight).fadeTo(1,fadeOver);
		},
		function() {
			$(currentLabel).hide();
			$(currentHighlight).fadeTo(1,fadeNormal);
			currentLoc = "";
			currentHighlight = "";
		}
	);
	$(".outer-label").click( function() {
		if (currentText == "") { 
			$(".text-box").show();
		}
		var previousText = currentText;
		currentText = "#" + currentLoc + "-text";
		var currentTitle = "#" + currentLoc + "-label";
		var currentBackground = $(currentHighlight).css("background-color");
		if (previousText != currentText) {
			var titleHtml = $(currentTitle).html();
			var textHtml = $(currentText).html();
			$("#titlebar").css("background-color",currentBackground);
			$("#title-cell").html(titleHtml);
			$("#text-cell").html(textHtml);
			resetAnimations();
		}
	});
	$("#closer-cell").click( function() {
		$(".text-box").hide();
		resetAnimations();
		currentText = "";
	});
});

function authorClick () {
	$("#credentials").fadeIn(500);
}


function credentialsClick () {
	$("#credentials").fadeIn(500, function () {
		$("#credentials").animate({
			top: "74px",
			height: "17px"
		},500, function() {
			$("#credentials-zoomed").fadeIn(500, function () {
				$("#credentials").animate({
					left: "2px",
					height: "34px",
					width: "222px",
					fontSize: "14px"
				}, 500);
			});
		});
		
	});
}

var citationAnimLevel = 0;

function animateCitationFirst () {
	$("#intext-citation").fadeIn(500);
	$("#intext-citation").animate({
		width: "120px",
		height: "20px",
		fontSize: "14px"
	}, 500); 
	citationAnimLevel = 1;
}

function animateCitationSecond () {
	/* if (citationAnimLevel == 0) {
		animateCitationFirst ();
	} */

	if ($("#reference-citation").css("display") != "none") {
		/*$("#reference-citation").hide();
		$("#reference-citation").css({
			left: "568px",
			height: "30px",
			width: "154px",
			fontSize: "5px"
		}) ; */
		resetAnimations();
	}

	$("#intext-citation").fadeIn(500, function () {
		$("#intext-citation").animate({
			width: "120px",
			height: "20px",
			fontSize: "14px"
		}, 500, function () { 
			$("#reference-citation").fadeIn(500, function () {	
				$("#intext-citation").animate({
					top: "416px",
					left: "568px",
					height: "26px",
					width: "150px"
				}, 1000);
				$("#intext-citation").fadeOut(500, function () {
					$("#reference-citation-zoomed").fadeIn(500);
					$("#reference-citation").animate({
						left: "430px",
						height: "60px",
						width: "308px",
						fontSize: "11px"
					}, 500, function () {
						$("#intext-citation").css({
							top: "396px",
							left: "36px",
							height: "10px",
							width: "60px",
							fontSize: "7px"
						});
					}); 
				});
			});
		});
	});
	citationAnimLevel = 2;
}

function hideJournalTitle () {
	if ($("#j-title").css("display") != "none") {
		$("#j-title").animate({
			left: "45px",
			height: "6px",
			width: "233px",
			fontSize: "6px"
		},500, function () {
			$("#j-title").fadeOut(500);
		});
	}
	else {
		$("#j-title").hide();
		$("#j-title").css({
			left: "45px",
			height: "6px",
			width: "233px",
			fontSize: "6px"
		});
	}
}

function hideJournalPages () {
	if ($("#j-pages").css("display") != "none") {
		$("#j-pages").animate({
			left: "273px", 
			height: "6px",
			width: "33px",
			fontSize: "6px"
		},500, function () {
			$("#j-pages").fadeOut(500);
		});
	}
	else {
		$("#j-pages").hide();
		$("#j-pages").css({
			left: "273px", 
			height: "6px",
			width: "33px",
			fontSize: "6px"
		});
	}
}

function animateJournalPages () {
	hideJournalTitle();
	$("#j-pages").fadeIn(500, function () {
		$("#j-pages").animate({
			left: "240px", 
			height: "16px",
			width: "66px",
			fontSize: "12px"
		},500);
	});
}

function animateJournalTitle () {
	hideJournalPages();
	$("#j-title").fadeIn(500, function () {
		$("#j-title").animate({
			left: "20px",
			height: "16px",
			width: "450px",
			fontSize: "12px"
		},500);
	});
}




function resetAnimations () {
	if ($("#intext-citation").css("display") != "none") {
		$("#intext-citation").animate({
			top: "396px",
			left: "36px",
			height: "10px",
			width: "60px",
			fontSize: "7px"
		},500, function() {
			$("#intext-citation").fadeOut(500);
		});
	}
	else {
		$("#intext-citation").hide();
		$("#intext-citation").css({
			top: "396px",
			left: "36px",
			height: "10px",
			width: "60px",
			fontSize: "7px"
		});
	}

	if ($("#reference-citation").css("display") != "none") {
		$("#reference-citation").animate({
			left: "568px",
			height: "30px",
			width: "154px",
			fontSize: "5px"
		},500, function() {
			$("#reference-citation").fadeOut(500);
		});
	}
	else {
		$("#reference-citation").hide();
		$("#reference-citation").css({
			left: "568px",
			height: "30px",
			width: "154px",
			fontSize: "5px"
		});
	}
	if ($("#credentials").css("display") != "none") {
		$("#credentials").fadeOut(500, function () {
			$("#credentials").css({
				top: "65px",
				left: "57px",
				height: "37px",
				width: "111px",
				fontSize: "7px"
			});
			$("#credentials-zoomed").hide();
		});
	}
	else {
		$("#credentials").hide();
		$("#credentials").css({
			top: "65px",
			left: "57px",
			height: "37px",
			width: "111px",
			fontSize: "7px"
		});
	}
	
	hideJournalTitle();
	hideJournalPages();
}