<?

	/////////////////////////////////////////////////
	$SiteRoot = "../";
	include $SiteRoot . "includes/includes.php";
	/////////////////////////////////////////////////

	// Header
	include $SiteRoot."includes/header.php";

	// Begin Template
	$tp = new PhpTemplate;
	for($tp->StartFromFile("index.template"); $tp->NextAndEchoOutput(); )
	{
		CheckGlobalEscapes($tp);
		if($tp->IsEscape("STORIES"))
		{
			// Constants
			$storylen = strlen(":STORY");
			$onindex = 0;
			
			// Read it
			$f = fopen("bible-stories.info", "r");
			
			// Load all lines
			while(($line = fgets($f, 4096)) != FALSE)
			{
				// Trim
				$line = trim($line);
				$len = strlen($line);
				
				// If it is blank
				if($line == "") continue;

				// If we are on a story
				if($len >= $storylen && substr($line, 0, $storylen) == ":STORY")
				{
					// Parse out the title
					$title = substr($line, $storylen + 1);
					$onindex++;
					
					// Run the template
					ExStory($tp->GetEscapeArgument(), $title, $onindex);
				}
			}
			
			// Close
			fclose($f);
		}
	}

	// Footer
	include $SiteRoot."includes/footer.php"; 

	//
	// Execute the story
	function ExStory($escape, $title, $onindex)
	{
		// Begin Template
		$tp = new PhpTemplate;
		for($tp->Start($escape); $tp->NextAndEchoOutput(); )
		{
			CheckGlobalEscapes($tp);
			if($tp->IsEscape("TITLE")) echo $title;
			else if($tp->IsEscape("TITLE-URI")) echo str_replace(" ", "_", $title);
		}
	}
	
?>