<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" indent="no"/>
	<xsl:include href="prc_th1_navigation.xsl"/>
	<xsl:include href="prc_th1_pag_general.xsl"/>
	<xsl:include href="prc_th1_com_shell.xsl"/>
	<xsl:include href="prc_th1_pag_home.xsl"/>
	<xsl:include href="prc_th1_pag_sitemap.xsl"/>
	<xsl:include href="prc_th1_pag_search.xsl"/>
	<xsl:include href="tracker.xsl" />

<!-- START VARIABLES -->
	
	<xsl:variable name="import"><xsl:value-of select="/page/@import"/></xsl:variable>

	<xsl:variable name="state">site</xsl:variable>
	
	<xsl:variable name="currentpage" select="/page/@id"/>
	
	<xsl:variable name="currentpagename" select="document(concat('pag_xml.php?id=', $currentpage))/page/name"/>
	
	<xsl:variable name="contentpage" select="$currentpage"/>
	
	<xsl:variable name="homepage" select="document(concat('sit_xml.php?id=', $site))/site/prc/navigation/utilitynav/page[1]/@id"/>
	
	<xsl:variable name="site" select="/page/@siteid"/>
	
	<xsl:variable name="parentsite" select="$site"/>
	
	<xsl:variable name="level">
		<xsl:for-each select="document(concat('sit_xml.php?id=', $site))/descendant::page[@id=$currentpage]">
			<xsl:value-of select="count(ancestor-or-self::page)"/>
		</xsl:for-each>
	</xsl:variable>
	
	<xsl:variable name="navtype">
		<xsl:for-each select="document(concat('sit_xml.php?id=', $site))/descendant::page[@id=$currentpage]">
			<xsl:value-of select="name(ancestor::*[number($level)])"/>
		</xsl:for-each>
	</xsl:variable>
	
	<xsl:variable name="section">
		<xsl:for-each select="document(concat('sit_xml.php?id=', $site))/descendant::page[@id=$currentpage]">
			<xsl:if test="name(ancestor::*[number($level)]) = 'globalnav'">global</xsl:if>
			<xsl:if test="name(ancestor::*[number($level)]) = 'quicknav'">quick</xsl:if>
			<xsl:if test="name(ancestor::*[number($level)]) = 'utilitynav'">utility</xsl:if>
			<xsl:if test="name(ancestor::*[number($level)]) = 'coursenav'">course</xsl:if>
		</xsl:for-each>
	</xsl:variable>	
	
	<xsl:variable name="primarypage">
		<xsl:for-each select="document(concat('sit_xml.php?id=', $site))/descendant::page[@id=$currentpage]">
			<xsl:choose>
			<xsl:when test="$level = 3">
			<xsl:value-of select="ancestor::page[number(2)]/@id"/>
			</xsl:when>
			<xsl:when test="$level = 2">
			<xsl:value-of select="ancestor::page[number(1)]/@id"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="$currentpage"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:variable>
	
	<xsl:variable name="pos">
		<xsl:for-each select="document(concat('sit_xml.php?id=', $site))/descendant::page[@id=$primarypage]">
			<xsl:number />
		</xsl:for-each>
	</xsl:variable>
	
	<xsl:variable name="primaryname">
		<xsl:value-of select="document(concat('pag_xml.php?id=', $primarypage))/page/name"/>
	</xsl:variable>
	
	<xsl:variable name="secondarypage">
		<xsl:for-each select="document(concat('sit_xml.php?id=', $site))/descendant::page[@id=$currentpage]">
			<xsl:choose>
			<xsl:when test="$level = 3">
			<xsl:value-of select="ancestor::page[number(1)]/@id"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="$currentpage"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:variable>
	
	<xsl:variable name="secondaryname">
		<xsl:value-of select="document(concat('pag_xml.php?id=', $secondarypage))/page/name"/>
	</xsl:variable>



<!-- END VARIABLES -->	

	<xsl:template match="page">
		<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;</xsl:text>
		<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">		
			<head>
				<title><xsl:value-of select="document(concat('sit_xml.php?id=', @siteid))/site/title"/></title>
				<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
                                <xsl:element name="base"><xsl:attribute	name="href"><xsl:value-of select="document(concat('sit_xml.php?id=', @siteid))/site/basehref"/></xsl:attribute></xsl:element>
				<link href="prc_css/universal.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="css/color_css.php?id={$site}" rel="stylesheet" media="screen" type="text/css"/>
				<link href="prc_css/universal_contentstyle.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="prc_css/{document(concat('sit_xml.php?id=', @siteid))/site/prc/@theme}.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="prc_css/{document(concat('sit_xml.php?id=', @siteid))/site/prc/@theme}_pal{document(concat('sit_xml.php?id=', @siteid))/site/palette}.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="prc_css/universal.css" rel="stylesheet" media="print" type="text/css"/>
				<link href="prc_css/universal_contentstyle.css" rel="stylesheet" media="print" type="text/css"/>
				<link href="prc_css/print.css" rel="stylesheet" media="print" type="text/css"/>
				<xsl:comment><![CDATA[[if IE]><link rel="stylesheet" type="text/css" media="screen" href="prc_css/style_ie.css" /><![endif]]]></xsl:comment>
									
				<xsl:element name="script"><xsl:attribute name="type">text/JavaScript</xsl:attribute><xsl:attribute name="src">js/dhtml.js</xsl:attribute><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></xsl:element>
				<xsl:element name="script"><xsl:attribute name="type">text/JavaScript</xsl:attribute><xsl:attribute name="src">js/mouse_over.js</xsl:attribute><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></xsl:element>
				<xsl:element name="script"><xsl:attribute name="type">text/JavaScript</xsl:attribute><xsl:attribute name="src">js/mm.js</xsl:attribute><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></xsl:element>
        <script type="text/javascript">if (window.attachEvent) window.attachEvent("onload", sfHover);</script>
			</head>
			<xsl:element name="body">
			  <xsl:attribute name="class">
          <xsl:choose>
            <xsl:when test="$currentpage = $homepage">
              <xsl:text>home</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>global</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>			
				<div id="wrapper">
					<ul id="globalnav" class="clearfix">
						<xsl:apply-templates select="document(concat('sit_xml.php?id=', @siteid))/site/prc/navigation/globalnav"/>
						<li style="border: none !important">&#160;</li>
					</ul>	
					<xsl:choose>
					<xsl:when test="$currentpage = $homepage">	
					<div id="header" style="background-image: url({document(concat('sit_xml.php?id=', @siteid))/site/prc/image/@filename})">
						<div id="logo-holder">
							<xsl:element name="img">
							<xsl:choose>
							<xsl:when test="document(concat('sit_xml.php?id=', @siteid))/site/prc/logo/@filename">
							<xsl:attribute name="src"><xsl:value-of select="document(concat('sit_xml.php?id=', @siteid))/site/prc/logo/@filename"/></xsl:attribute>
							</xsl:when>
							<xsl:otherwise>
							<xsl:attribute name="src">images/default_prc_logo.gif</xsl:attribute>
							</xsl:otherwise>
							</xsl:choose>
							<xsl:attribute name="id"><xsl:text>prc-logo</xsl:text></xsl:attribute>
							<xsl:attribute name="alt"><xsl:text>Public Resource Center Logo</xsl:text></xsl:attribute>
							</xsl:element>
						</div>
						<h1><xsl:value-of select="document(concat('sit_xml.php?id=', @siteid))/site/name" disable-output-escaping="yes"/></h1>
            <xsl:if test="count( document(concat('sit_xml.php?id=', @siteid))/site/prc/navigation/quicknav/page ) > 0">
              <div id="home-quicknav" style="display: block !important">
              <form>
                <xsl:apply-templates select="document(concat('sit_xml.php?id=', @siteid))/site/prc/navigation/quicknav"/>	
              </form>
              <form action="search.php" method="post">
                <fieldset>
                <h3><label for="search">Search by keyword</label></h3>
                <input type="hidden" name="site" value="{@siteid}" />
                <input type="hidden" name="type" value="prc" />
                <input type="text" name="searchtxt" id="search"/><button type="submit" title="Search"><img src="images/icon_search.gif" alt="Search"/></button>
                </fieldset>
              </form>			
              </div>
            </xsl:if>
						<p><xsl:value-of select="document(concat('sit_xml.php?id=', @siteid))/site/description" disable-output-escaping="yes"/></p>
						<ul id="topicnav" class="clearfix">
							<xsl:apply-templates select="document(concat('sit_xml.php?id=', @siteid))/site/prc/navigation/sitenav"/>
						</ul>
					</div>		
					</xsl:when>
					<xsl:otherwise>	
					<div id="header" style="background-image: url({document(concat('sit_xml.php?id=', @siteid))/site/prc/image/@filename})">
						<div id="logo-holder">
							<xsl:element name="img">
							<xsl:choose>
							<xsl:when test="document(concat('sit_xml.php?id=', @siteid))/site/prc/logo/@filename">
							<xsl:attribute name="src"><xsl:value-of select="document(concat('sit_xml.php?id=', @siteid))/site/prc/logo/@filename"/></xsl:attribute>
							</xsl:when>
							<xsl:otherwise>
							<xsl:attribute name="src">images/default_prc_logo.gif</xsl:attribute>
							</xsl:otherwise>
							</xsl:choose>
							<xsl:attribute name="id"><xsl:text>prc-logo</xsl:text></xsl:attribute>
							<xsl:attribute name="alt"><xsl:text>Public Resource Center Logo</xsl:text></xsl:attribute>
							</xsl:element>
						</div>
						<h1><xsl:value-of select="document(concat('sit_xml.php?id=', @siteid))/site/name" disable-output-escaping="yes"/></h1>
					</div>	
					<xsl:element name="div">
						<xsl:attribute name="id">subnav</xsl:attribute>
						<xsl:attribute name="class"><xsl:text> clearfix</xsl:text></xsl:attribute>
            <xsl:variable name="sitenav" select="document(concat('sit_xml.php?id=', @siteid))/site/prc/navigation/sitenav"/>
            <xsl:for-each select="$sitenav/page">
              <xsl:variable name="pagxml" select="document(concat('pag_xml.php?id=',@id))"/>
              <xsl:variable name="pagpos" select="position()"/>

              <xsl:element name="h2">
                <xsl:attribute name="class">
                  <xsl:text>page</xsl:text><xsl:value-of select="@id"/> <xsl:text> t</xsl:text><xsl:value-of select="position()"/>
                  <!-- need to switch class so arrow will point down -->
                  <xsl:if test="current()/descendant-or-self::page[@id=$currentpage]">
                    <xsl:text> current</xsl:text>
                  </xsl:if>
                </xsl:attribute>
                <a href="page.php?id={@id}"><xsl:value-of select="$pagxml/page/name"/></a>
              </xsl:element>
              
              <!-- This should be recursing -->
              <xsl:choose>
                <!-- Is this the current page? If so, spit out level 2 links -->
                <xsl:when test="current()[@id=$currentpage] and current()/page">
                  <ul>
                  <xsl:for-each select="current()/page">
                    <li><a href="page.php?id={@id}"><xsl:value-of select="document(concat('pag_xml.php?id=',@id))/page/name"/></a></li>
                  </xsl:for-each>
                  </ul>
                </xsl:when>
                
                <!-- Is the current page a descendant of this page? If so, spit out level 2 and test each for current-ness -->
                <xsl:when test="current()/descendant::page[@id=$currentpage] and current()/page">
                  <ul>
                  <xsl:for-each select="current()/page">
                    <xsl:element name="li">
                      <xsl:if test="current()[@id=$currentpage]">
                        <xsl:attribute name="class"><xsl:text>current</xsl:text></xsl:attribute>
                      </xsl:if>
                      <a href="page.php?id={@id}"><xsl:value-of select="document(concat('pag_xml.php?id=',@id))/page/name"/></a>
                      <!-- next case -->
                      <xsl:choose>
                        <!-- Is this the current page? If so, spit out level 3 (final) links -->
                        <xsl:when test="current()[@id=$currentpage] and current()/page">
                          <ul>
                            <xsl:for-each select="current()/page">
                              <li><a href="page.php?id={@id}"><xsl:value-of select="document(concat('pag_xml.php?id=',@id))/page/name"/></a></li>
                            </xsl:for-each>
                          </ul>
                        </xsl:when>
                        <!-- If none are current page, it must be in level 3 links -->
                        <xsl:when test="current()/page[@id=$currentpage] and current()/page">
                          <ul>
                            <xsl:for-each select="current()/page">
                              <xsl:element name="li">
                                <xsl:if test="current()[@id=$currentpage]">
                                  <xsl:attribute name="class"><xsl:text>current</xsl:text></xsl:attribute>
                                </xsl:if>
                                <a href="page.php?id={@id}"><xsl:value-of select="document(concat('pag_xml.php?id=',@id))/page/name"/></a>
                              </xsl:element>
                            </xsl:for-each>
                          </ul>
                        </xsl:when>
                      </xsl:choose>
                    </xsl:element>
                  </xsl:for-each>
                  </ul>
                </xsl:when>
              </xsl:choose>

            </xsl:for-each>
						<div id="sub-quicknav">
						<form action="search.php" method="post">
							<fieldset>
								<h3><label for="search">Search by keyword</label></h3>
                				<input type="hidden" name="site" value="{@siteid}" />
                				<input type="hidden" name="type" value="prc" />
								<input type="text" name="searchtxt" id="search"/><button type="submit" title="Search"><img src="images/icon_search.gif" alt="Search"/></button>
							</fieldset>
						</form>		
						</div>
					</xsl:element>
					</xsl:otherwise>
					</xsl:choose>
					<div id="shadow">
					</div>	
					<div id="content">
					<xsl:apply-templates select="globalnavpage"/>	
					<xsl:apply-templates select="sitenavpage"/>	
					<xsl:apply-templates select="utility"/>	
					<xsl:apply-templates select="quicknavpage"/>	
					<xsl:apply-templates select="home"/>	
					<xsl:apply-templates select="sitemap"/>	
					<xsl:apply-templates select="search"/>	
					&#160;
					</div>
					<div id="footer" class="clearfix">
						<img src="images/cte.gif"/><!-- img src="images/jhu.gif"/ -->
						<xsl:if test="@siteid = 1261"><img src="images/msde_logo.jpg" /></xsl:if>
						<xsl:if test="@siteid = 2481"><img src="images/msde_logo.jpg" /></xsl:if>
						<xsl:apply-templates select="document(concat('sit_xml.php?id=', @siteid))/site/prc/navigation/utilitynav"/>	
					</div><br/>			
				</div>				
  			<xsl:call-template name="tracker"/>	
			</xsl:element> <!-- end BODY -->
		</html>
	</xsl:template>
	
</xsl:stylesheet>

