<?

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

	// Get the id
	$xpath = split(".php", $HTTP_SERVER_VARS["REQUEST_URI"]);
	if(!isset($xpath[1])) $xpath[1] = "/";
	$xnothing = split("\.", substr($xpath[1], 1), 2);
	$id = $xnothing[0];
	if($id == "") $id = request("id");

	// Constants
	$id = str_replace("_", " ", $id);
	$storylen = strlen(":STORY");
	$title = "";
	$html = "";
	
	// 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);

			// Is this us
			if($title != $id) continue;
			
			// Loop all the lines
			while(($line = fgets($f, 4096)) != FALSE)
			{
				// Trim
				$line = trim($line);

				// If it is blank
				if($line == ":ENDSTORY") break;
				
				// Append
				$html .= $line;
			}
			
			// Done
			break;
		}
	}

	// Close
	fclose($f);

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

	// Begin Template
	$tp = new PhpTemplate;
	for($tp->StartFromFile("story.template"); $tp->NextAndEchoOutput(); )
	{
		CheckGlobalEscapes($tp);
		if($tp->IsEscape("STORY")) echo $html;
		else if($tp->IsEscape("TITLE")) echo $title;
	}

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