var bMac = (navigator.userAgent.indexOf('Mac') != -1) ? true : false; 
var bOpera = (navigator.userAgent.indexOf('Opera') != -1) ? true : false; 

function supportDblClick() {
	return (!bMac && !bOpera);
}

function goThere(sel) {
	if (!sel || sel.options.selectedIndex < 0) {
		alert("You must make a choice first.");
		return;
	} else {
		var theURL = (sel.options[sel.options.selectedIndex]).value;
		if (theURL.indexOf("../interactive/arcade.htm") != -1) {
			popArcade();
			return;
		} else if (theURL.indexOf("../interactive/medal.htm") != -1) { 
			popMedal();
			return;
		} else if (theURL.indexOf("../interactive/mobile.htm") != -1) { 
			popMobile('../');
			return;
		} else if (theURL.indexOf("../interactive/cake.htm") != -1) { 
			popCake('../');
			return;
		} else if (theURL == "#" || theURL == "") {
			return;
		} else {
			document.location = theURL;
		}
	}
}

function navSubmit() {
	goThere(document.frmNav.url); 
	return false;
}

function swapThumb(sel) {
	var idx = sel.options.selectedIndex;
	if (idx >= 0) {
		swapImage("artThumb", artThumbs[idx+1]);
	} else {
		return;
	}
}

function swapImage(strElement, objImage) {	
// this function swaps the image identified by strElement for a new one preloaded as objImage
	if (document.images && objImage && objImage.src && objImage.src != "") {
		if (document.images[strElement]) {
			document.images[strElement].src = objImage.src;
		}
	}
}

function onArt() {
	swapImage('interArt', artworkOn);
}

function offArt() {
 swapImage('interArt', artworkOff);
}

function onInqCaption(num, artCaptions, artHighlights) {
	swapImage('interArtCaption', artCaptions[num]);
	swapImage('interArt', artHighlights[num]);
}

function offInqCaption(artCaptions, artHighlights) {
	swapImage('interArtCaption', artCaptions[0]);
	swapImage('interArt', artHighlights[0]);
}

function onArtCaption(num, artCaptions) {
	onArt();
	swapImage('interArtCaption', artCaptions[num]);
}

function offArtCaption(artCaptions) {
	swapImage('interArtCaption', artCaptions[0]);
}

function onOverview(num) {
	if (overviewScreen) swapImage('navScreen', overviewScreen[num]);
}

function offOverview() {
	if (overviewScreen) swapImage('navScreen', overviewScreen[0]);
}

function popPlayer(filename) {
	playerWindow = window.open(filename,'audioPopup','width=410,height=160,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	playerWindow.focus();
	return false;
}

function popArcade() {
	playerWindow = window.open('/education/classroom/interactive/arcade.htm','arcadePop','width=710,height=586,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	playerWindow.focus();
	return false;
}

function popMedal() {
	playerWindow = window.open('/education/classroom/interactive/medal.htm','medalPop','width=710,height=573,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	playerWindow.focus();
	return false;
}

function popCake(path) {
	if (!path) path = "";
	playerWindow = window.open(path + 'interactive/cake.htm','cakePop','width=710,height=522,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	playerWindow.focus();
	return false;
}

function popMobile(path) {
	if (!path) path = "";
	playerWindow = window.open(path + 'interactive/mobile.htm','mobilePop','width=710,height=499,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	playerWindow.focus();
	return false;
}

function customAlert(msg) {
	var path = '../alert_' + msg + '.htm';
	alertWin = window.open(path,'alertPop','width=410,height=150,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	alertWin.focus();
	return false;
}

function popCredits() {
	creditsWindow = window.open('/education/classroom/credits.htm','creditsPop','width=410,height=150,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	creditsWindow.focus();
	return false;
}

function popImage(path, w, h, scrollbars) {
	w = w + 50; // account for margins
	h = h + 77; // account for margins + color stripe
	if (!scrollbars) scrollbars = 0;
	imagePopup = window.open(path,'imagePop','width=' + w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scrollbars + ',resizable=1');
	if (imagePopup.outerHeight) {
		imagePopup.outerHeight = h+25;
		imagePopup.outerWidth = w;
	} else {
		imagePopup.resizeTo(w, h+25);
	}
	imagePopup.focus();
	return false;
}

function popZoom(path, w, h) {
	w = w + 50; // account for margins
	h = h + 130; // account for margins + color stripe
	zoomPopup = window.open(path,'imagePop','width=' + w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1');
	if (zoomPopup.outerHeight) {
		zoomPopup.outerHeight = h+25;
		zoomPopup.outerWidth = w;
	} else {
		zoomPopup.resizeTo(w, h+25);
	}
	zoomPopup.focus();
	return false;
}

function ngaAlert(msg, w, h) {
	if (!w) w = 440;
	if (!h) h = 150;
	alertWin = window.open('alerts/alert_' + msg + '.htm','alertPop','width=' + w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	alertWin.focus();
	
	//alert(msg);
	return false;
}

function feedbackAnswer( correct, field ){
	if( correct ){
		alert('Congratulations! Your answer is correct!');
		field.checked = true;
	}else{
		alert('Sorry, that answer is incorrect.  Please try again!');
		field.checked = false;
	}
}

function verifyTextAnswer(answer, field){
	var result = field.value;
	result == answer ? alert('Congratulations! Your answer is correct!') : alert('Sorry, that answer is incorrect.  Please try again!');
	return false;
}

function verifyNumberAnswer(answer, presice, field){
	if( presice ){
		var result = field.value;
	}else{
		var result = Math.round(Number(field.value));
	}
	(result == answer) ? alert('Congratulations! Your answer is correct!') : alert('Sorry, that answer is incorrect.  Please try again!');
	return false;
}

function arrayContains (a, o) {
	for (var i = 0; i < a.length; i++) {
		if (a[i] == o) {
			return true;
		}
	}
	return false;
}