<?php 
  $pieces = explode("/", getcwd());
  $name = end($pieces);
?>


<?php
  $db = mysql_connect('localhost', 'joe', 'fixture');
  $db_selected = mysql_select_db('udn', $db);
  if (!$db or !$db_selected) {
    die('Could not connect: ' . mysql_error());
  }

  $result = mysql_query(sprintf(
    "select * from gallery where name = '%s'",
    mysql_real_escape_string($name)
  ));
  $page = mysql_fetch_assoc($result);

  $resultForNext = mysql_query(sprintf(
    "select * from gallery where title >= '%s' order by title",
    mysql_real_escape_string($page["title"])
  ));
  $nextpage = mysql_fetch_assoc($resultForNext );
  $nextpage = mysql_fetch_assoc($resultForNext );

  $resultForPrevious = mysql_query(sprintf(
    "select * from gallery where title < '%s' order by title desc",
    mysql_real_escape_string($page["title"])
  ));
  $previouspage = mysql_fetch_assoc($resultForPrevious);



  $result = mysql_query(sprintf("select * from images where gallery_id = %d order by sequence", $page["id"]));
  while ($row = mysql_fetch_assoc($result)) {
    $images[] = $row;
  }

 $category_list = array(
    "Bars & Restaurants" => "/archive/BarsRestaurants.php",
    "Airports" => "/archive/Airports.php", 
    "Business" => "/archive/Business.php", 
    "Hotels" => "/archive/Hotels.php", 
    "Cool Installations"  => "/archive/CoolInstallations.php", 
    "Vessels" => "/archive/Vessels.php", 
    "National Parks" => "/archive/NationalParks.php", 
    "Landmarks" => "/archive/NationalParks.php", 
    "Private Residence" => "/archive/PrivateResidence.php",
    "Sporting & Concert Venues" => "/archive/SportingConcertVenues.php", 
    "Museums" => "/archive/Museums.php", 
    "Eductional Institutions" => "/archive/EductionalInstitutions.php",
    "Public" => "/archive/Public.php", 
    "Women's" => "/archive/Womens.php",
    "Miscellaneous" => "/archive/Miscellaneous.php"
  );

 $category_titles = array(
  "Airports" => "Airports, Train Stations, Sea Ports",
  "Hotels" => "Hotels & Casinos",
  "National Parks" => "Parks",
  "Cool Installations" => "Top 1,000 Urinals",
  "Public" => "Public Facilities",
  "Educational Institutions" => "Schools and Universities",
  "Private Residences" => "Private Residences",
  "Sporting & Concert Venues" => "Sporting, Concert, and Other Venues",
  "Women's" => "Women's Installations"
);


  function title($page) { 
    if ($page["extended_title"]) {
      return $page["title"];
    } else {
      return "The Urinals of " . $page["title"];
    }
  }
?>
<!DOCTYPE html>
<!--[if IE 7 ]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8 oldie"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->

<head>

    

    <title><?php print strip_tags(title($page)) ?></title>

    <?php include 'http://urinal.net/style/head.php' ?>
   <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
   <script type="text/javascript" src="/style/mapping.js"></script>
   <script>var oldIE = false;</script>
<!--[if lte IE 8]><script>oldIE = true;</script><![endif]-->
</head>

<body id="top" onload="initPage('<?php print str_replace("'", "", $page["location"]) ?>');">

<!-- header
============================================================================= -->

<div id="header-wrap" style="height: 130px";><header style="height: 0;">

	   <div style="position:absolute; top: 85px; left: 10px">
	       <h1><?php print title($page) ?></h1>

		
          </div>


		<?php include 'http://urinal.net/style/header.php' ?>	
		
</header>
</div>


<div>
<div id="extra">
		<h3><?php print $page["subtitle"] ?></h3>
		Filed under:
		<?php
			$categories = split("\|", $page["categories"]);
			$count = 0;
			
  			foreach ($categories as $category) {
				$display = array_key_exists($category, $category_titles) ? $category_titles[$category] : $category;
				printf("%s<a href=\"%s\">%s</a>", ($count++ > 0 ? " | " : ""), $category_list[$category], $display);
			}
		?>

</div>
</div>

<?php include 'http://urinal.net/style/socialBar.php' ?>

<?php include 'http://urinal.net/style/bannerAd.php' ?>

<!-- Content
============================================================================== -->
<div id="content-wrap" style="padding: 1px 0 35px;">
    <!-- main -->
    <section id="main" style="margin-top: 0;">

        <article class="post">

			<?php
  function draw_image($image) {
    printf("<div class=\"image-section\"><img src=\"%s\" width=\"%d\" height=\"%d\"></div>\n", 
      $image["src"], $image["width"], $image["height"]);
    printf("<p>%s</p>\n", $image["comment"]);
  }
  $total_image_height = 0;
  foreach ($images as $image) {
    draw_image($image);
    $total_image_height += $image["height"];
  }
?>

			
			
        </article>

     

    <!-- /main -->
    </section>
    <!-- sidebar -->
    <aside id="sidebar">


				<div class="sidemenu">
					<h3>Explore</h3>
					<ul>
						<li id="mapli"><a href="#" onClick="Slide();">Location</a><p>
							<div id="actuatorDiv" title="Click for map"></div>
							<div id="captionDiv" title="Click for map" onClick="Slide();"></div></li>
						<li><a href="/<?php print $nextpage["name"] ?>/">Next Urinal</a>
							<span>Next alphabetical location</span></li>
						<li><a href="/<?php print $previouspage["name"] ?>/">Previous Urinal</a>
							<span>Previous alphabetical location </span></li>
						<li><a href="/">Home</a>
							<span>Back to the main page</span></li>
					</ul>
				</div>


				
	<!-- /sidebar -->
	</aside>

</div>

<!-- extra
============================================================================== -->
<div id="extra-wrap"><div id="extra" class="clearfix">


<div id="fb-root"></div>
<script>(function(d){
  var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  js = d.createElement('script'); js.id = id; js.async = true;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  d.getElementsByTagName('head')[0].appendChild(js);
}(document));</script>
<div class="fb-comments" data-href="urinal.net<?php print $_SERVER['REQUEST_URI'] ?>" data-num-posts="2" data-width="800" data-colorscheme="dark"></div>
</div></div>

<!-- footer
============================================================================== -->
<footer class="clearfix">

	<p class="footer-left">
		<a href="/copyright.html">&copy; <?php print $page["copyright"] ?> - Urinal Dot Net</a>
	</p>

	<p class="footer-right">
	   	<a href="/">Home</a> |
        <a class="back-to-top" href="#top">Back to Top</a>
    </p>

<!-- /footer -->
</footer>



</body>
</html>

