// 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] = "At Eastwell Manor in Kent, England, the remaining five teams learned that their next challenge dealt with a secret society whose ideas have influenced the world. Following instructions, they headed back across the English Channel to the village of Peille, France.";
	story[2] = "Once there, the teams were instructed to make a grueling climb to the top of Peille Gorge. However, they did have one option: 150 miles away in the town of Saint Tropez was a statue of American revolutionary Pierre Andre de Suffren that held a clue to an alternate route. There was one more thing they needed to know: The secret society used the symbol of an inverted rose to mark the path to hidden treasures; the first team to locate the symbol would win a $50,000 bonus. ";
	story[3] = "Because Melissa of team Miss USA had hurt her arm while digging during the last task, Miss USA decided to drive to Saint Tropez. Other teams had worries of their own. Team Genius' Sam was afraid of heights and worried about his asthma, but his teammates insisted that they make the climb.";
	story[4] = "It was an arduous trek up the mountain, complete with a rope bridge spanning the gorge. Air Force was in first place as they scaled up a rock wall with the Southie Boys following behind. The third place Geniuses climbed the first wall and paused at the second suspension bridge to give Sam a chance to rest as last-place Ex-CIA played catch-up.";
	story[5] = "At the top, Air Force reached a cave where they found a ring of keys that would help them unlock the next clue, along with a picture of a castle that revealed their next destination.";
	story[6] = "In Saint Tropez, Miss USA found the statue and a parchment instructing them to return to the village of Peille where they were to follow a path leading to the clue. As they headed out of town, they were happy with their decision, thinking they were way ahead of the other teams.";
	story[7] = "Sam got halfway up the mountain and stopped. After five minutes, he still couldn't muster the strength to go on, completely derailing the Geniuses' progress as he hyperventilated on the mountain face. With some encouragement from his friends, Sam put hand over hand and pulled himself up the rest of the way.";
	story[8] = "Air Force located the castle, noticing a group of loose rocks that hid a piece of paper with the words, \"The ancient Roman ruin crumbles on the hillside on La Turbie.\" The Southie Boys also located the castle, but struggled to find the note. Instead, they attempted to use the keys to try and open a locked gate.";
	story[9] = "The Southie Boys were still at it when the Geniuses arrived at the castle with Ex-CIA close behind. When Miss USA finally arrived at the castle, the other teams were out in the woods, two miles away, still trying to figure out the clue. In a matter of seconds, the girls found a loose rock and withdrew the next clue, putting them in second place.";
	story[10] = "Air Force arrived at the La Turbie ruins, but couldn't find the next clue until they broke it down to its essentials and looked by the hillside, where they located the inverted rose. A little more searching led them to a chest containing the $50,000. A message from Laird provided them an old map of Paris and instructions to head to the City of Lights to search for their next location.";
	story[11] = "Back at Peille, the three wayward teams returned to the castle and almost immediately found the loose rocks with the message directing them to La Turbie.";
	story[12] = "Miss USA was on a roll and quickly found the box on the hillside of La Turbie, where they received their next instructions from Laird.";
	story[13] = "Ex-CIA, the Geniuses, and the Southie Boys arrived at La Turbie, with Ex-CIA being the first of the three to find the clue. With sportsmanlike aplomb, Ex-CIA waived over the other two teams and they were all soon on their way to Paris.";
	story[14] = "In Paris, a notation on their map led Air Force to visit Champs de Mars, located next to the Eiffel Tower. Reaching the famous landmark, Laird sent a message about a secret society made of world leaders, philosophers, and artists. One of them created a classic symbol of American freedom that could be seen from the second platform of the Eiffel tower. Reaching the platform, they looked to the west to see a replica of the Statue of Liberty.";
	story[15] = "At the statue, Air Force found a message that said, \"Clean the streets of Paris to find your path.\" Using a cloth and a bucket, they cleaned their map, which revealed a clue about the Rosicrucian Order. Getting in a car by the statue, Air Force headed to the ancient society's headquarters.";
	story[16] = "By the time Miss USA reached the viewing platform, it was already night and they couldn't see the Statue of Liberty off in the distance. Meanwhile, the other three teams were on a Metro train where they noticed that their maps were made of some kind of strange paper. Pouring water on it, they discovered the next clue.";
	story[17] = "Air Force was first to arrive at the Rosicrucian headquarters located at the Chateau D'Omonville in Normandy, France. They soon found a room containing dozens of boxes. Using their keys, they started unlocking them until they found Thomas Jefferson's cryptex - the sixth artifact.";
	story[18] = "The Geniuses, Ex-CIA, and the Southie Boys decided to skip the Statue of Liberty and head straight to Normandy. The Geniuses were the first of the three teams to arrive and they quickly found the lockboxes and one of the cryptexes, putting them in second place. The Southie Boys were next to find an artifact, with Ex-CIA bringing up the rear.";
	story[19] = "Miss USA finally realized that they were looking for the Statue of Liberty when they saw its image on a post card at a tourist shop. But by the time they realized they had to use water to wash away the map and reveal the next clue, it was too late. With all the cryptexes already found, Miss USA became the next team to be sent home.";
	
	///// IMAGE LOCATIONS GO IN EACH VARIABLE /////
	var imgs = new Array();
	imgs[1] = "/Treasure_Hunters/images/recap/107/th_107_01.jpg";
	imgs[2] = "/Treasure_Hunters/images/recap/107/th_107_02.jpg";
	imgs[3] = "/Treasure_Hunters/images/recap/107/th_107_03.jpg";
	imgs[4] = "/Treasure_Hunters/images/recap/107/th_107_04.jpg";
	imgs[5] = "/Treasure_Hunters/images/recap/107/th_107_05.jpg";
	imgs[6] = "/Treasure_Hunters/images/recap/107/th_107_06.jpg";
	imgs[7] = "/Treasure_Hunters/images/recap/107/th_107_07.jpg";
	imgs[8] = "/Treasure_Hunters/images/recap/107/th_107_08.jpg";
	imgs[9] = "/Treasure_Hunters/images/recap/107/th_107_09.jpg";
	imgs[10] = "/Treasure_Hunters/images/recap/107/th_107_10.jpg";
	imgs[11] = "/Treasure_Hunters/images/recap/107/th_107_11.jpg";
	imgs[12] = "/Treasure_Hunters/images/recap/107/th_107_12.jpg";
	imgs[13] = "/Treasure_Hunters/images/recap/107/th_107_13.jpg";
	imgs[14] = "/Treasure_Hunters/images/recap/107/th_107_14.jpg";
	imgs[15] = "/Treasure_Hunters/images/recap/107/th_107_15.jpg";
	imgs[16] = "/Treasure_Hunters/images/recap/107/th_107_16.jpg";
	imgs[17] = "/Treasure_Hunters/images/recap/107/th_107_17.jpg";
	imgs[18] = "/Treasure_Hunters/images/recap/107/th_107_18.jpg";
	imgs[19] = "/Treasure_Hunters/images/recap/107/th_107_19.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];
		}
		
	

}