// JavaScript Document

window.onload=function(){
	document.getElementById('galleryInfo').innerHTML='\
	<form id="holder" name="holder" action="" method="post">\
	<input type="hidden" name="show">\
	</form>';
	
	// Get the url information
	var locate = window.location
	document.getElementById('holder').show.value = locate
	var text = document.holder.show.value
	
	// Parse out the url information
	theleft = text.indexOf("=") + 1;
	theright = text.length; // for 1 variable
	sText = (text.substring(theleft, theright));
	
	///// STORY COPY GOES HERE IN EACH VARIABLE /////
///// STORY COPY GOES HERE IN EACH VARIABLE /////
	var story = new Array();
	story[1] = "Only the Geniuses, the Southie Boys, and Air Force remained as they prepared to set out on their last adventure. Every artifact collected along the way would have to be used to find the seventh and final artifact.";
	story[2] = "The teams headed out to the Library of Congress, the first step on the last leg of their journey. Arriving first gave the Southies an edge. When they stepped into the library, Laird told them to find one of three books to reveal the key to the treasure - \"Poltroons & Patriots,\" \"Official Histories,\" or \"The American Flag: Of Stars and Stripes.\"";
	story[3] = "The Geniuses were second to arrive; the Southies decided to follow them to see how they went about seeking out the books. Soon after, Air Force ran into the building to begin their quest for one of the three books.";
	story[4] = "All three teams converged at the massive card catalog with Air Force first to find one of the book's locations. They quickly found the book and realized that the clue wasn't the book itself, but its location. Behind the book was the seventh artifact - a leather-bound portfolio containing a series of maps and charts. Laird told them it held the key to the final treasure, a key that was in front of them every step of the way.";
	story[5] = "The clues led Air Force to the \"old printing press\" where they found a printing plate containing spaces for all the artifacts collected along the way. They used the plate and the old printing press to print a treasure map of the Battle of Baltimore from the War of 1812. With a call from Laird, they took off to Fort McHenry for the next leg of their journey.";
	story[6] = "The Geniuses were next to find the last artifact. They took off to the printing press where they made their own map leading them to Fort McHenry.";
	story[7] = "Meanwhile, the Southies struggled to find one of the books and the portfolio that contained their next clue. At last, they found the portfolio and were off to the old printing press where they printed a map of their own.";
	story[8] = "Air Force got lost on the way to Fort McHenry and stopped at a firehouse to ask for directions. There, the firemen let them use a computer and also told them that Francis Scott Key wrote \"The Star Spangled Banner\" on a truce ship near Fort McHenry.";
	story[9] = "The Air Force's pause at the firehouse allowed the Geniuses to arrive at their destination first. There, they got on a boat that took them out to the truce ship where Scott Key wrote the United State's national anthem.";
	story[10] = "Inside a glass pane, the Geniuses found a coin and a piece of parchment with a picture of a key and the words, \"The treasure is not here. The answer is right in front of you.\" Another clue told them to head to the location where the Lazaretto Battery once stood.";
	story[11] = "Air Force finally arrived at the docks and headed out to the truce ship where they become second to find the next clue. They were off and running to the Lazaretto Battery while the Southie Boys were still on the road to the Fort.";
	story[12] = "On the water, the Geniuses had no idea where the Lazaretto Battery used to be. Finally, Sam spotted an industrial building with a big sign for \"Key Industries\" above an American flag. Laird told them to seek out and gain access to a hidden chamber located deep within the structure. Inside the chamber, they had to solve the five-letter cryptex. What it contained would point the way to the treasure.";
	story[13] = "As the Geniuses searched for the chamber and Air Force looked for the Battery, the Southie Boys finally arrived at the truce ship where they received their next clue. Soon, they too were on their way to the Key Industries building.";
	story[14] = "Bingo. Francis found a sliding door that led them down into the bowels of the building where the locked door to the chamber awaited. Placing their medallion artifact into a slot on the door, the door unlocked and slid open, giving them access to the mysterious chamber.";
	story[15] = "Air Force discovered the Key Industries building, making them the second team to arrive. Following in the Geniuses' footsteps, they climbed the staircase that ran along the building's side just as the third-place Southies were arriving fast on their heels. To be continued...";
	
	
	///// IMAGE LOCATIONS GO IN EACH VARIABLE /////
	var imgs = new Array();
	imgs[1] = "/Treasure_Hunters/images/recap/109/th_109_01.jpg";
	imgs[2] = "/Treasure_Hunters/images/recap/109/th_109_02.jpg";
	imgs[3] = "/Treasure_Hunters/images/recap/109/th_109_03.jpg";
	imgs[4] = "/Treasure_Hunters/images/recap/109/th_109_04.jpg";
	imgs[5] = "/Treasure_Hunters/images/recap/109/th_109_05.jpg";
	imgs[6] = "/Treasure_Hunters/images/recap/109/th_109_06.jpg";
	imgs[7] = "/Treasure_Hunters/images/recap/109/th_109_07.jpg";
	imgs[8] = "/Treasure_Hunters/images/recap/109/th_109_08.jpg";
	imgs[9] = "/Treasure_Hunters/images/recap/109/th_109_09.jpg";
	imgs[10] = "/Treasure_Hunters/images/recap/109/th_109_10.jpg";
	imgs[11] = "/Treasure_Hunters/images/recap/109/th_109_11.jpg";
	imgs[12] = "/Treasure_Hunters/images/recap/109/th_109_12.jpg";
	imgs[13] = "/Treasure_Hunters/images/recap/109/th_109_13.jpg";
	imgs[14] = "/Treasure_Hunters/images/recap/109/th_109_14.jpg";
	imgs[15] = "/Treasure_Hunters/images/recap/109/th_109_15.jpg";

	//alert(imgs[1].indexOf(".jpg"));
	
	
	///// STORY PROCESSES /////
	var sCount = imgs.length;
	var cPages = "";
	var	cNext = parseFloat(sText);
	var sTextNum = parseFloat(sText);
	
	///// FORCE AN ID IF NONE IS GIVEN /////
	if(isNaN(sTextNum)){
		sTextNum = 1;
		cNext = 1;
	}
	
	
	///// CHECKS THE SET VALUES FOR CORRECT VIEWING /////
	if(sText){
		cNext = cNext+1;
		cCopy = sTextNum;
		cBack = sTextNum - 1;
		
		if(sTextNum == 0){ // checks for 0 
			cBack = sCount - 1;		
			sText = 1;
		}
		if(sTextNum == 1){ // checks for 1
			cBack = sCount - 1;		
			sText = 1;
		}
		if(cNext > (sCount-1)){ // next turnaround
			cNext = 1;
			sText = cCopy;
			cBack = sCount-1;	
		}
		if(cBack == sText){ // back turnaround 
			cNext = 1;
			sText = cCopy;
			cBack = cBack-1;	
		}
	}else{
		cBack = sCount - 1;
		cNext = 2;
		sCount = 1
		sText = 1;
	}
	if(sCount ==  sTextNum){
		cNext = 1;
	}
	
	
	///// SET ID INFORMATION FOR HTML ELEMENTS /////
	pCopy = document.getElementById('copy');
	pNext = document.getElementById('goNext');
	pBack = document.getElementById('goBack');
	pPicList = document.getElementById('picList');
	pPicListNext = document.getElementById('picListNext');
	pPicListBack = document.getElementById('picListBack');
	
	
	// Checks and sets the setCount
	var setCount = 1;
	if(pPicList){
		setCount = parseFloat(pPicList.title);
	
		if(!setCount){
			setCount=1;
		}
	}
	
	///// THUMBNAILS /////
	if(pPicList){		
		// Set initial vairables for thumbnails
		var thumbNail = "";		
		id = cCopy - ((cCopy -1) % setCount);
		alert(cCopy);
		setLimit = id + setCount;
			
			// Write out the thumbnails
			for(id; id < setLimit; id++){
				if(imgs[id]){
					thumbNail = thumbNail + "\
						<a href='?id="+id+"'><img src='"+imgs[id].replace(".jpg" ,"_sm.jpg")+"' alt='"+story[id]+"' /></a>";
				}
			}
		
			// Writes Thumbnails to the page
			pPicList.innerHTML = thumbNail; 
		
			
			//tBack = (sCount-id);
			
			//alert(sCount);
			if(id >= sCount){
				id=setCount;
				//tBack = setCount;
			}
			
			if(id == sCount){
				//tBack = sCount - setCount;
				id=setCount;
			}
			
			if(setLimit > setCount){
				tBack = (sCount-1) - setCount;	
			}
			
			if(setLimit == (setCount+1)){
				tBack = (sCount+1) - setCount;	
			}
			
			if(setLimit < sCount){
				tBack = (id-setCount)-setCount;
			}
			if(tBack <= 1){
				tBack = sCount-1;
			}
		}
		
		
		////// CHECK AND BALANCE FOR HTML ELEMENTS /////
		for(i=0; i < document.anchors.length; i++){
		
			// Writes out the "Next" link
			if(document.anchors[i].name == "goNext"){
				document.anchors[i].href="?id="+cNext;
			}
			
			// Writes out the "Back" link
			if(document.anchors[i].name == "goBack"){
				document.anchors[i].href="?id="+cBack;	
			}
			if(pPicList){
				if(setCount != sCount-1){
					// Writes out the "Thumbnail Next" link
					if(document.anchors[i].name == "picListNext"){
						document.anchors[i].href="?id="+id;					
					}
					
					// Writes out the "Thumbnail Back" link
					if(document.anchors[i].name == "picListBack"){
						document.anchors[i].href="?id="+tBack;		
					}
				}
			}
							
		}
		
		
	
		// Writes in the Main Image Source
		document.images.mainImg2.src=imgs[cCopy]; 
		
		//Writes out the story copy
		if(pCopy){
			pCopy.innerHTML=story[sText];
		}
		
	

}