modules = new Object();
answers = new Object();
currentModule = 0;
currentActivity = 0;
currentQuestion = 0;
blinkCount = 0;
intervalID = 0;

modules["M1"] = "Stratification and Biodiversity in Pennsylvania's Northeastern Deciduous Forest";
modules["M2"] = "Raptor Migration &#8212; Local, Cooperative and Global";
modules["M3"] = "Sea Turtle Hatchling Orientation from Nest to Ocean";
modules["M4"] = "The Biology and Plight of the Leatherback";
modules["M5"] = "Amphibians as Indicators of Environmental Change";
modules["M6"] = "Invasive Plant Species in Pennsylvania";
modules["M7"] = "Global Warming: Turning Up the Heat";

function showNotebook() 
{
	var fs = document.getElementById("frameset1");
	if (fs) {
		fs.rows = "*,100%";
		if (window.frames["notebook"])
			window.frames["notebook"].focus();
	}
}

function hideNotebook() 
{
	var fs = document.getElementById("frameset1");
	if (fs) {
		fs.rows = "100%,*";
		if (window.frames["main"])
			window.frames["main"].focus();
	}
}

function writeNote() 
{
	var dstf = window.frames["notebook"];
	var srcf = window.frames["main"];
	if (!dstf) {
		//alert("--Error Missing Notebook Frame--");
		return;
	}
	if (!srcf) {
		//alert("--Error Missing Source Frame--");
		return;
	}
	var nb = dstf.document.getElementById("notes");
	if (!nb) {
		//alert("--Error Missing Progressive Notebook--");
		return;
	}
	var module = dstf.document.getElementById("M"+currentModule);
	if (!module) {
		module = dstf.document.createElement("div");
		module.id = "M"+currentModule;
		module.innerHTML = "<p class=\"moduleTitle\">" + modules[module.id] + "</p>";
		nb.appendChild(module);
	}
	var activity = dstf.document.getElementById(module.id+"A"+currentActivity);
	if (!activity) {
		activity = dstf.document.createElement("div");
		activity.id = module.id+"A"+currentActivity;
		activity.innerHTML = "<p class=\"activityTitle\">" + srcf.ActivityTitle + "</p>";
		module.appendChild(activity);
	}
	var note = dstf.document.getElementById(activity.id+"Q"+currentQuestion);
	if (!note) {
		note = dstf.document.createElement("p");
		note.id = activity.id+"Q"+currentQuestion;
		activity.appendChild(note);
	}
	var question = srcf.questions[currentQuestion];
	if (question) {
		note.innerHTML = "<em>" + question + "</em>";
	}
	var node = dstf.document.createElement("blockquote");
	var answer = srcf.document.getElementById("answer");
	if (answer) {
		node.innerHTML = answer.value.replace(/\n/g,"<br/>");
		answers[note.id] = answer.value;
	} else {
		node.innerHTML = "<em>--Error Missing Answer Block--</em>";
	}
	note.appendChild(node);
}

function showCurrentQuestion()
{
	var srcf = window.frames["main"];
	if (!srcf) {
		//alert("--Error Missing Source Frame--");
		return;
	}
	var qblock = srcf.document.getElementById("question");
	if (qblock) {
		var question = srcf.questions[currentQuestion];
		if (question) {
			qblock.innerHTML = question;
		} else {
			qblock.innerHTML = "";
		}
	}
	var dblock= srcf.document.getElementById("directions");
	if (dblock) {
		var n = currentDirection;
		var direction = srcf.directions[n];
		if (direction) {
			if(navigator.appName == "Microsoft Internet Explorer") {
				blinkCount = 0;
				intervalID = setInterval('blinkIt()',500);
			}
		}
		while (direction == null && n > 0) {
			direction = srcf.directions[--n];
		}
		if (direction) {
			dblock.innerHTML = "<span>"+direction+"</span>";
		}
		if (!question) {
			dblock.innerHTML = "Go on to the next page.";
		}
	}
	var answerbox = srcf.document.getElementById("answer");
	if (answerbox) {
		var answer = answers["M"+currentModule+"A"+currentActivity+"Q"+currentQuestion];
		if (answer) {
			answerbox.value = answer;
		} else {
			answerbox.value = "";
		}
	}
	var ablock = srcf.document.getElementById("answerBlock");
	if (ablock) {
		if (!question) {
			ablock.style.display = "none";
		} else {
			ablock.style.display = "block";
		}
	}
}
function nextQuestion()
{
	if (currentQuestion == null) {
		currentQuestion = 0;
		currentDirection = 0;
	} else {
		var srcf = window.frames["main"];
		if (srcf && currentQuestion < (srcf.questions.length - 1)) {
			currentQuestion += 1;
			currentDirection += 1;
		}
	}
	showCurrentQuestion();
}
function prevQuestion()
{
	if (currentQuestion == null) {
		currentQuestion = 0;
		currentDirection = 0;
	} else if (currentQuestion > 0) {
		var srcf = window.frames["main"];
		currentQuestion -= 1;
		currentDirection -= 1;
	}
	showCurrentQuestion();
}
function startPage()
{
	var srcf = window.frames["main"];
	if (srcf) {
		currentQuestion = null;
		currentActivity = srcf.ActivityNum;
		currentModule = srcf.ModuleNum;
		nextQuestion();
	}
}

function popUp(URL) {

            eval("definitions = window.open(URL, 'definitions', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=200,left = 570,top = 325');");

            definitions.focus();

}


function blinkIt() {
	//This function crudely attempts to make the directions field blink a few times when the directions change.
	var srcf = window.frames["main"];
	for(i=0;i<srcf.document.all.tags('span').length;i++){
		s=srcf.document.all.tags('span')[i];
		if (blinkCount <= 3) {
			s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
		} else {
			s.style.visibility='visible';
			clearInterval(intervalID);
		}
		blinkCount++;
	}
}

