/* -------------------------- */
/* DEATH IN A GLASS FUNCTIONS */
/* -------------------------- */

score = 0;
selectedAnswerIndex = -1;

function showAnswer(k) {
	currentQuestion = "question" + k;
	answerQuestion = currentQuestion + "-answer";
	
	// Gets the index of the currently selected radio button
	for (i=0;i<document.getElementsByName(currentQuestion).length;i++){
		if (document.getElementsByName(currentQuestion)[i].checked==true) {
		selectedAnswerIndex = i;
		}
	}
	
	// This checks to make sure they made a selection
	if (selectedAnswerIndex < 0){
		alert("You need to select an answer!");
		return false;
	}
	
	// This switches the header depending on whether they selected the right answer
	answerValue = document.getElementsByName(currentQuestion)[selectedAnswerIndex].value;
	if(answerValue == 0){
		document.getElementById("quizHeader").src = "/images/exhibits/quiz-incorrect.gif";
	} else {
		document.getElementById("quizHeader").src = "/images/exhibits/quiz-correct.gif";
	}
	
	// Switch to the answer
	document.getElementById("questionContent").innerHTML = document.getElementById(answerQuestion).innerHTML;
	
	//Set score
	score = parseInt(score) + parseInt(answerValue);
	//document.getElementById("currentScore").innerHTML = "Your Current Score is: " + score;
	
	// Reset's the selectionIndex for the next question
	selectedAnswerIndex = -1;
}
function nextQuestion(k){
	currentQuestion = "question" + k;
	questionHeaderSrc = "/images/exhibits/quiz-"+currentQuestion+".gif";
	document.getElementById("quizHeader").src = questionHeaderSrc;
	document.getElementById("questionContent").innerHTML = document.getElementById(currentQuestion).innerHTML;
}
function finish(){
	document.getElementById("quizHeader").src = "/images/exhibits/quiz-results.gif";
	document.getElementById("finalScore").innerHTML = score+"/15";
	document.getElementById("questionContent").innerHTML = document.getElementById("quizResults").innerHTML;
}
function btnRollover(k){
	btnRolloverState = "/images/exhibits/quiz-"+k+"-on.gif";
	document.getElementById("quizButton").src = btnRolloverState;
}
function btnRolloff(k){
	btnRolloffState = "/images/exhibits/quiz-"+k+".gif";
	document.getElementById("quizButton").src = btnRolloffState;
}

// Dictionary Terms for Death in a Glass
var glassTerms = new Array();
glassTerms['bacteria'] = 'single-celled organisms that lack a true nucleus and reproduce by splitting off or by dividing into two identical cells; some bacteria cause diseases';
glassTerms['baffles'] = 'devices that control the flow of water';
glassTerms['beneficial'] = 'having good effects';
glassTerms['brackish'] = 'a mixture of seawater (salt water) and fresh water';
glassTerms['cesspit'] = 'a pit for sewage and garbage';
glassTerms['chlorinated'] = 'treated with chlorine, to kill bacteria and other microorganisms';
glassTerms['contaminated'] = 'made impure by contact with something unclean';
glassTerms['cyst'] = 'a closed sac made of living tissue, containing fluid or semi-fluid matter';
glassTerms['epidemic'] = 'an outbreak of disease that spreads quickly and affects many people in one area';
glassTerms['faeces'] = 'solid waste matter passed out from the body';
glassTerms['gastroenteritis'] = 'inflammation of the stomach and intestines';
glassTerms['hemolytic_uremic_syndrome'] = 'a condition that causes anemia (low red blood cell count), and a decrease in blood platelets, along with kidney failure';
glassTerms['hypothesis'] = 'a proposal, intended to explain certain facts or observations, that can be tested to determine its accuracy';
glassTerms['microorganisms'] = 'forms of life that can be seen only with the help of a microscope and that usually are made up of a single cell';
glassTerms['nuclei'] = 'the plural of nucleus, the central region of a cell where DNA is stored.';
glassTerms['parasite'] = 'an organism that lives off another organism';
glassTerms['paratyphoid'] = 'an infectious disease of the intestine, similar to typhoid, which causes fever, diarrhea, and abdominal pain';
glassTerms['perpetrator'] = 'one who commits a (usually criminal or outrageous) action';
glassTerms['proteins'] = 'complex molecules made up of amino acids';
glassTerms['protozoan'] = 'single-celled, usually microscopic organisms that live in water or as parasites, whose cells contain a distinct membrane-bound nucleus, or centre';
glassTerms['reservoirs'] = 'natural or artificial ponds or lakes used to store water';
glassTerms['symptoms'] = 'signs of a disorder, disease, or illness';
glassTerms['torrential'] = 'pouring in a large amount, like a torrent';
glassTerms['toxoplasmosis'] = 'a disease caused by the bacteria <em>Toxoplasma gondii</em>';
glassTerms['turbidity'] = 'muddiness created by stirring up sediment';
glassTerms['unpasteurized'] = 'not exposed to high temperatures designed to kill bacteria';
glassTerms['virus'] = 'a micro-organism smaller than a bacteria and that can live only by invading other cells';
glassTerms['symptom'] = 'what an ill person experiences as a result of a particular disease';
glassTerms['unpasteurized'] = 'not exposed to temperatures high enough to kill disease-causing bacteria';

// Donno what this does but it detects IE properly
var IE = document.all?true:false;
var isPopped = new Boolean(false);

function pageLoad() {
	// Trigger mouse handler
	document.onmousemove = mouseMoved;
	//document.getElementById('popDiv').innerHTML = "Hello World";
}
function mouseMoved(evt) {
	if (isPopped==true) {
		
		// Positioning is figured out by: "mousePosition" + "documentScrollOffset" +/- "desiredOffset"
		
		if (IE) {
			//alert("ie");
			//alert("Top Scroll Offset:" + document.documentElement.scrollTop + "; Left Scroll Offset:"+document.documentElement.scrollLeft);
			document.getElementById('popDiv').style.top = event.clientY + document.documentElement.scrollTop + 25;
			document.getElementById('popDiv').style.left = event.clientX + document.documentElement.scrollLeft - 100;
			document.getElementById('popDiv').style.display = "block";
		} else {
			//alert("not ie");
			document.getElementById('popDiv').style.position = "absolute";
			document.getElementById('popDiv').style.top = evt.clientY + 25 + window.scrollY +"px";
			document.getElementById('popDiv').style.left = evt.clientX - 100 + window.scrollX +"px";
			document.getElementById('popDiv').style.display = "block";
		}
	}else {
			document.getElementById('popDiv').style.display = 'none';
			document.getElementById('popDiv').innerHTML = "";
			document.getElementById('popDiv').style.top = 0;
			document.getElementById('popDiv').style.left = 0;
		}
}
function showTerm(txtTerm) {
	isPopped = true;
	description = glassTerms[txtTerm.toLowerCase()];
	fullTerm = "<dl><dt>"+txtTerm+":<dt><dd>"+description+"</dd></dl>";
	document.getElementById('popDiv').innerHTML = fullTerm;
}
function hideTerm() {
	isPopped = false;
	document.getElementById('popDiv').style.display = 'none';
	document.getElementById('popDiv').innerHTML = "";
}


/* --------------------------- */
/* JOINT REPLACEMENT FUNCTIONs */
/* --------------------------- */

function hideAllSubSections() {
	document.getElementById('sorbie').style.display = 'none'; 
	document.getElementById('wevers').style.display = 'none' ; 
	document.getElementById('tassos').style.display = 'none' ; 
	document.getElementById('csmall').style.display = 'none' ; 
	document.getElementById('pichora').style.display = 'none' ; 
	document.getElementById('ellis').style.display = 'none' ;
}
function showSubSection(section){
	document.getElementById(section).style.display = 'block';
}
function InsertMovie() {
	document.write('<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="320" height="255" codebase="http://www.apple.com/qtactivex/qtplugin.cab">')
	document.write('<param name="src" value="http://chin.istorm.ca/joints/video/understanding-motion.mov">')
	document.write('<param name="autoplay" value="true">')
	document.write('<param name="controller" value="true">')
	document.write('<param name="loop" value="true">')
	document.write('<EMBED src="http://chin.istorm.ca/joints/video/understanding-motion.mov" width="320" height="255" autoplay="true" controller="true" loop="true" pluginspage="http://www.apple.com/quicktime/download/">')
	document.write('</EMBED>')
	document.write('</OBJECT>')
}
function picturePopUp(picURL, picWidth, picHeight) {
		day = new Date();
		id = day.getTime();
		window.open(picURL, id,'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+picWidth+',height='+picHeight+',left = 193,top = 129');
	}
function showMaterial(material) {
	document.getElementById('cobaltChromiumAlloy').style.display = 'none';
	document.getElementById('plastic').style.display = 'none' ;
	document.getElementById('ceramic').style.display = 'none';
	document.getElementById('titanium').style.display = 'none';
	document.getElementById(material).style.display = 'block';
}
function rolloverPast(tgt) {
	target = tgt+"Rollover";
	targetImg = "../../images/exhibits/"+tgt+"-on.jpg";
	//alert(target +":"+targetImg);
	document.getElementById(target).src = targetImg;
}
function hidePast() {
	document.getElementById('glassRollover').src = '../../images/exhibits/glass-off.jpg';
	document.getElementById('woodRollover').src = '../../images/exhibits/wood-off.jpg';
	document.getElementById('ivoryRollover').src = '../../images/exhibits/ivory-off.jpg';
}
