//Browser Detection

if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4) {
	var isIE4 = true
	var isNS4 = false
}
else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4) {
	var isIE4 = false
	var isNS4 = true
}
else {
	var isIE4 = false
	var isNS4 = false
}



if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 5") >= 0) {
	var isIE5 = true
}
else {
	var isIE5 = false
}






//Detect platform

var version_and_platform = navigator.appVersion

if (version_and_platform.indexOf("Mac") >= 0) {
	var isMac = true
	var isPC = false
}
else if (version_and_platform.indexOf("Win") >= 0) {
	var isMac = false
	var isPC = true
}
else {
	var isMac = false
	var isPC = false
}




var subW = ""





function enlargeSW(x) {
		closeSW()
		subW = window.open("","view_window","left=0,top=0,scrollbars=yes,location=no,status=no,resizable=yes,toolbar=no,height=" + (parseInt(theItem.imagesHeight[x]) + 80) + ",width=" + (theItem.imagesWidth[x]))

		subW.document.write("<HTML>")
		subW.document.write("<HEAD>")
		subW.document.write("<TITLE>Enlarged Image</TITLE>")
		subW.document.write("</HEAD>")
		subW.document.write("<BODY BGCOLOR=cccc99 LEFTMARGIN=0 TOPMARGIN=0>")
		if (isNS4) {
			subW.document.write("<SPAN STYLE='position: absolute; left: 0px; top: 0px; z-index: 1'>")
		}
		subW.document.write("<IMG SRC='" + theItem.imagesLarge[x] + "' BORDER=0>")
		if (isNS4) {
			subW.document.write("</SPAN>")
		}
		subW.document.write("<br><br><A HREF='javascript: window.close()'><IMG SRC='images/close_win.gif' BORDER=0></A>")
		subW.document.write("</BODY>")
		subW.document.write("</HTML>")
		subW.document.close()
		subW.focus()
		
}










function incorrect(x) {

	var z = "<TABLE BORDER=0>"
	z += "<TR VALIGN=center>"
	z += "<TD ALIGN=center>"
	
	z += "<TABLE BORDER=0>"
	z += "<TR>"
	z += "<TD WIDTH>"
	z += "<SPAN CLASS=textTimes>"
	z += "<IMG SRC='" + theItem.imagesMed[x] + "' BORDER=0>"
	z += "<BR>" + theItem.imageSubTitles[x] + ", "
	z += theItem.imageInfo[x] + "<P>"
	z += "</SPAN>"
	z += "</TD>"
	z += "</TR>"
	z += "</TABLE>"
	
	z += "<br><A HREF='javascript: window.close()'><IMG SRC='images/try_again.gif' BORDER=0></A>"

	z += "</TD>"
	
	z += "<TD WIDTH>"

	var temp = "<SPAN CLASS=textReg>"
	temp += "<B>Not a Curtis photograph</B><BR><BR>"
	temp += "<I>HINT: </I>"
	temp += theItem.imageObservations[x]
	temp += "</SPAN>"

	z += rTextBox(temp,219)
	z += "</FONT>"
	z += "</TD>"
	
	z += "</TR>"
	z += "</TABLE>"
	
	return z

}


function rTextBox(text,tWidth) {

	var z = "<table cellpadding=0 border=0 cellspacing=0 width=" + (tWidth + 62) + ">"
	z += "<tr>"
	z += "<td><IMG SRC='images/title/text_box_top_left.gif'></td>"
	z += "<td><IMG SRC='images/title/text_box_top_mid.gif' width=" + tWidth + " height=30></td>"
	z += "<td><IMG SRC='images/title/text_box_top_right.gif'></td>"
	z += "</tr>"
	z += "<tr><td colspan=3>"
	z += "<table cellpadding=0 border=0 cellspacing=0 width=" + (tWidth + 62) + ">"
	z += "<tr><td bgcolor=666666 width=1><IMG SRC='images/title/shim.gif' width=1 height=1></td>"
	z += "<td bgcolor=ffffcc width=10><IMG SRC='images/title/shim.gif' width=10 height=1></td>"

	z += "<td bgcolor=ffffcc width=" + (tWidth + 40) + ">"
	z += text
	z += "</td>"

	z += "<td bgcolor=ffffcc width=10><IMG SRC='images/title/shim.gif' width=10 height=1></td>"
	z += "<td bgcolor=666666 width=1><IMG SRC='images/title/shim.gif' width=1 height=1></td></tr>"
	z += "</table>"
	z += "<tr>"
	z += "<td><IMG SRC='images/title/text_box_bot_left.gif'></td>"
	z += "<td><IMG SRC='images/title/text_box_bot_mid.gif' width=" + tWidth + " height=30></td>"
	z += "<td><IMG SRC='images/title/text_box_bot_right.gif'></td>"
	z += "</tr>"
	z += "</table>"

	return z
}





function rTextBox_testCopy(text,tWidth) {

	var z = "<table cellpadding=0 border=1 cellspacing=0 width=" + (tWidth + 62) + ">"
	z += "<tr>"
	z += "<td><IMG SRC='images/title/text_box_top_left1.gif'></td>"
	z += "<td><IMG SRC='images/title/text_box_top_mid.gif' width=" + tWidth + " height=15></td>"
	z += "<td><IMG SRC='images/title/text_box_top_right1.gif'></td>"
	z += "</tr>"
	z += "<tr><td colspan=3>"
	z += "<table cellpadding=0 border=0 cellspacing=0 width=" + (tWidth + 62) + ">"
	z += "<tr valign=top height=15><td colspan=2 width=18 height=15><IMG SRC='images/title/text_box_top_left2.gif'></td>"

	z += "<td bgcolor=ffffcc width=" + (tWidth + 40) + " rowspan=3>"
	//z += text
	z += "</td>"
	
	z += "<td colspan=2 width=18 height=1%><IMG SRC='images/title/text_box_top_right2.gif'></td></tr>"

	z += "<tr valign=middle height=98%><td bgcolor=666666 width=1><IMG SRC='images/title/shim.gif' width=1 height=1></td>"
	z += "<td bgcolor=ffffcc width=17><IMG SRC='images/title/shim.gif' width=10 height=1></td>"
	z += "<td bgcolor=ffffcc width=17><IMG SRC='images/title/shim.gif' width=10 height=1></td>"
	z += "<td bgcolor=666666 width=1><IMG SRC='images/title/shim.gif' width=1 height=1></td></tr>"
	
	z += "<tr valign=bottom><td colspan=2 width=18 bgcolor=ffffcc><IMG SRC='images/title/text_box_bot_left2.gif'></td>"
	z += "<td colspan=2 width=18 bgcolor=ffffcc><IMG SRC='images/title/text_box_bot_right2.gif'></td></tr>"
	
	z += "</table>"
	z += "<tr>"
	z += "<td><IMG SRC='images/title/text_box_bot_left1.gif'></td>"
	z += "<td><IMG SRC='images/title/text_box_bot_mid.gif' width=" + tWidth + " height=15></td>"
	z += "<td><IMG SRC='images/title/text_box_bot_right1.gif'></td>"
	z += "</tr>"
	z += "</table>"

	return z
}




function closeSW() {

	if (subW && !subW.closed) {
			subW.close()
	}
		
}




function resizeImage(x,w,h) {
	rWidth = theItem.imagesHeight[x]
	rHeight = theItem.imagesWidth[x]
	percent = 99
	while (rWidth > w || rHeight > h) {
		rWidth = parseInt(theItem.imagesWidth[x] * percent * .01)
		rHeight = parseInt(theItem.imagesHeight[x] * percent * .01)
		--percent
	}
	return "<IMG SRC='" + theItem.imagesLarge[x] + "' BORDER=0 WIDTH=" + rWidth + " HEIGHT=" + rHeight + ">"
}






function setSubCookie(cookieKey,subKey,subValue) {
	subValue = escape(subValue)
	if (document.cookie.indexOf(cookieKey) >= 0) {
		
		//get cookie
		var keyValuePairs = document.cookie.split("; ")
		for (var i=0; i < keyValuePairs.length; ++i) {
			var tempArray = keyValuePairs[i].split("=")
			if (tempArray[0] == cookieKey) {
				var theCookie = tempArray[1]
				break
			}
		}
		
		
		//get sub cookies
		var subKeyValuePairs = theCookie.split("&&")
		
		//update sub cookie
		for (var i=0; i < subKeyValuePairs.length; ++i) {
			var tempArray = subKeyValuePairs[i].split("::")
			if (tempArray[0] == subKey) {
				subKeyValuePairs[i] = tempArray[0] + "::" + subValue
				var newCookie = subKeyValuePairs.join("&&")
				document.cookie = cookieKey + "=" + newCookie
				return true
			}
		}
		
		//or, add sub cookie
		var newCookie = subKeyValuePairs.join("&&")
		document.cookie = cookieKey + "=" + newCookie + "&&" + subKey + "::" + subValue
		
	}
	else {
		document.cookie = cookieKey + "=" + subKey + "::" + subValue
		return true
	}
}








function retrieveSubCookie(cookieKey,cookieSubKey) {
	//Check for existence of cookie
	if (!document.cookie) {
		return false
	}


	//get cookie
	var keyValuePairs = document.cookie.split("; ")
	for (var i=0; i < keyValuePairs.length; ++i) {
		var tempArray = keyValuePairs[i].split("=")
		if (tempArray[0] == cookieKey) {
			var theCookie = tempArray[1]
			break
		}
	}
	
	
	if (!theCookie) {
		return false
	}
	
	
	//get sub cookie
	var subKeyValuePairs = theCookie.split("&&")
	for (var i=0; i < subKeyValuePairs.length; ++i) {
		var tempArray = subKeyValuePairs[i].split("::")
		if (tempArray[0] == cookieSubKey) {
			return unescape(tempArray[1])
		}
	}
	return false
}





function displaySet(selection) {

	if (retrieveSubCookie("curtis","set" + selection) == "yes") {
		location.href = "correct.html?" + selection
		return true
	}
	else {
		for (var i=1; i <= totalSets; ++i) {
			if (retrieveSubCookie("curtis","set" + i) == "active") {
				setSubCookie("curtis","set" + i,"no")
			}
		}
		setSubCookie("curtis","set" + selection,"active")
	}
	
	location.href = "puzzles.html?" + selection
	
}




function allCorrect() {

	//Check to see if all images have been correctly found
	var found = 0
	for (var i = 1; i <= totalSets; ++i) {
		if (retrieveSubCookie("curtis","set" + i) == "yes") {
			++found
		}
	}
	if (found == totalSets) {
		return true
	}
	else {
		return false
	}
	
}

