<?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_navigation.xsl"/>
	<xsl:include href="prc_item_contentobject.xsl"/>
	<xsl:include href="prc_item_course.xsl"/>
	<xsl:include href="prc_item_resource.xsl"/>
	<xsl:include href="prc_com_shell.xsl"/>

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

	<xsl:variable name="state">item</xsl:variable>
	
	<xsl:variable name="currentpage" select="/page/@id"/>
	
	<xsl:variable name="childsite" select="/page/*/@id"/>
	
	<xsl:variable name="parentsite" select="document(concat('pag_xml.php?id=', $currentpage))/page/@siteid"/>
	
	<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=', $parentsite))/site/prc/navigation/utilitynav/page[1]/@id"/>
	
	<xsl:variable name="site" select="/page/@siteid"/>		
	
	<xsl:variable name="level">
		<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/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=', $parentsite))/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=', $parentsite))/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=', $parentsite))/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=', $parentsite))/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=', $parentsite))/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=', $parentsite))/site/name"/></title>
				<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
				<link href="prc_css/universal.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="css/aos.css" 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=', $parentsite))/site/prc/@theme}.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: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>
			</head>
			<xsl:element name="body">
			<xsl:attribute name="class">
			<xsl:choose>
			<xsl:when test="$currentpage = $homepage"><xsl:text>global</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=', $parentsite))/site/prc/navigation/globalnav"/>
					</ul>	
					<div id="header" style="background-image: url({document(concat('sit_xml.php?id=', $parentsite))/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"><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=', $parentsite))/site/name"/></h1>
					</div>	
					<xsl:element name="div">
						<xsl:attribute name="id">subnav</xsl:attribute>
						<xsl:attribute name="class"><xsl:if test="$navtype = 'sitenav'">t<xsl:value-of select="$pos"/></xsl:if><xsl:text> clearfix</xsl:text></xsl:attribute>
						<h2 class=""><a href="page.php?id={$homepage}">&lt; Home</a><br/><br/>
						<xsl:value-of select="$primaryname"/></h2>
						<ul class="secondary">
							<xsl:call-template name="sidenav"/>
						</ul>
						<div id="sub-quicknav">
						<form action="search.php" method="post">
							<input type="hidden" name="site" value="{@siteid}" />
							<input type="hidden" name="type" value="prc" />
							<xsl:apply-templates select="document(concat('sit_xml.php?id=', @siteid))/site/prc/navigation/quicknav"/>	
							<fieldset>
								<h3><label for="search">Search by keyword</label></h3>
								<input type="text" name="searchtxt" id="search"/><button type="button" title="Search"><img src="images/icon_search.gif" alt="Search"/></button>
							</fieldset>
						</form>		
						</div>	
					</xsl:element>
					<div id="shadow">
					</div>	
					<div id="content">&#160;											
						<xsl:choose>
						<xsl:when test="name(/page/*) = 'site'">
						<xsl:apply-templates select="document(concat('sit_xml.php?id=', $childsite))/site/contentobject"/>
						<xsl:apply-templates select="document(concat('sit_xml.php?id=', $childsite))/site/course"/>
						</xsl:when>
						<xsl:otherwise>
						<xsl:apply-templates select="document(concat('res_xml.php?id=', $childsite))/resource"/>
						</xsl:otherwise>
						</xsl:choose>						
					</div>
					<div id="footer">
						<xsl:apply-templates select="document(concat('sit_xml.php?id=', $parentsite))/site/prc/navigation/utilitynav"/>
					</div><br/>
					<span id="copyright">Copyright &#169; JHU CTE Online Learning Management System 2005</span>				
				</div>				
			</xsl:element>
		</html>
	</xsl:template>
	
</xsl:stylesheet>

