<?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="course_navigation.xsl"/>
	<xsl:include href="course_item_contentobject.xsl"/>
	<xsl:include href="course_item_course.xsl"/>
	<xsl:include href="course_item_resource.xsl"/>
	<xsl:include href="course_com_shell.xsl"/>

<!-- START VARIABLES -->
	
	<xsl:variable name="condensed"><xsl:value-of select="/page/@condensed"/></xsl:variable>
	
	<xsl:variable name="import"><xsl:value-of select="/page/@import"/></xsl:variable>

	<xsl:variable name="state">item</xsl:variable>
	
	<xsl:variable name="childsite" select="/page/*/@id"/>
	
	<xsl:variable name="currentpage" select="/page/@id"/>
	
	<xsl:variable name="parentsite" select="document(concat('pag_xml.php?id=', $currentpage))/page/@siteid"/>
	
	<xsl:variable name="homepage" select="document(concat('sit_xml.php?id=', $parentsite ))/site/course/navigation/utilitynav/page[1]/@id"/>
	
	<xsl:variable name="parentname"><xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$currentpage]"><xsl:value-of select="name(parent::*)"/></xsl:for-each></xsl:variable>
	
	<xsl:variable name="currentpagetype">
		<xsl:if test="$parentname = 'globalnav'">session</xsl:if>
		<xsl:if test="$parentname = 'page'">activitypage</xsl:if>
		<xsl:if test="$parentname = 'quicknav'">quicknav</xsl:if>
		<xsl:if test="$parentname = 'utilitynav'">utility</xsl:if>
	</xsl:variable>
	
	<xsl:variable name="sessionrtf">
		<xsl:choose>
		<xsl:when test="$currentpagetype = 'session'">
			<xsl:value-of select="$currentpage"/>
		</xsl:when>
		<xsl:when test="$currentpagetype = 'activitypage'">
			<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$currentpage]">
				<xsl:value-of select="../../@id"/>
			</xsl:for-each>				
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="number(0)"/>
		</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="session" select="$sessionrtf"/>
	
	<xsl:variable name="sesposrtf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'session' or $currentpagetype = 'activitypage'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$session]">
					<xsl:value-of select="count(preceding-sibling::page) + 1"/>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="sespos" select="$sesposrtf"/>
	
	<xsl:variable name="activityrtf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'activitypage'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$currentpage]">
					<xsl:value-of select="../@id"/>
				</xsl:for-each>				
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="activity" select="$activityrtf"/>
	
	<xsl:variable name="actposrtf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'activitypage'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$activity]">
					<xsl:value-of select="count(preceding-sibling::page) + 1"/>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="actpos" select="$actposrtf"/>
	
	<xsl:variable name="activitypagertf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'activitypage'">
				<xsl:value-of select="$currentpage"/>			
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="activitypage" select="$activitypagertf"/>
	
	<xsl:variable name="pagposrtf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'activitypage'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$currentpage]">
					<xsl:value-of select="count(preceding-sibling::*) + 1"/>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="pagpos" select="$pagposrtf"/>
	
	<xsl:variable name="presesrtf">
		<xsl:choose>
			<xsl:when test="$sespos &gt; '1'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$session]">
					<xsl:value-of select="preceding-sibling::page[1]/@id"/>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="preses" select="$presesrtf"/>
	
	<xsl:variable name="folsesrtf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'activitypage' or $currentpagetype = 'session'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite ))/descendant::page[@id=$session]">
					<xsl:choose>
						<xsl:when test="following-sibling::page[1]/@id &gt; 0">
							<xsl:value-of select="following-sibling::page[1]/@id"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="number(0)"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="folses" select="$folsesrtf"/>
	
	<xsl:variable name="preactrtf">
		<xsl:choose>
			<xsl:when test="$actpos &gt; '0'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/descendant::page[@id=$activity]">
					<xsl:value-of select="preceding-sibling::page[1]/@id"/>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="preact" select="$preactrtf"/>
	
	<xsl:variable name="folactrtf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'activitypage' or $currentpagetype = 'session'">
				<xsl:choose>
					<xsl:when test="$currentpagetype = 'activitypage'">
						<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/descendant::page[@id=$activity]">
							<xsl:choose>
								<xsl:when test="following-sibling::page[1]/@id &gt; 0">
									<xsl:value-of select="following-sibling::page[1]/@id"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="number(0)"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:when>
					<xsl:otherwise>
						<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/descendant::page[@id=$session]">
							<xsl:choose>
								<xsl:when test="child::page[1]/@id &gt; 0">
									<xsl:value-of select="child::page[1]/@id"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="number(0)"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="folact" select="$folactrtf"/>
	
	<xsl:variable name="preactpagertf">
		<xsl:choose>
			<xsl:when test="$preact &gt; '0'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/descendant::page[@id=$preact]">
					<xsl:choose>
						<xsl:when test="child::page[1]/@id &gt; '0'">
							<xsl:value-of select="child::page[1]/@id"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="number(0)"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>		
	
	<xsl:variable name="preactpage" select="$preactpagertf"/>
	
	<xsl:variable name="folactpagertf">
		<xsl:choose>
			<xsl:when test="$folact &gt; '0'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/descendant::page[@id=$folact]">
					<xsl:choose>
						<xsl:when test="child::page[1]/@id &gt; '0'">
							<xsl:value-of select="child::page[1]/@id"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="number(0)"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>		
	
	<xsl:variable name="folactpage" select="$folactpagertf"/>	
	
	<xsl:variable name="prepagrtf">
		<xsl:choose>
			<xsl:when test="$pagpos &gt; '1'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/descendant::page[@id=$currentpage]">
					<xsl:value-of select="preceding-sibling::page[1]/@id"/>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="prepag" select="$prepagrtf"/>	
	
	<xsl:variable name="folpagrtf">
		<xsl:choose>
			<xsl:when test="$currentpagetype = 'activitypage'">
				<xsl:for-each select="document(concat('sit_xml.php?id=', $parentsite))/descendant::page[@id=$currentpage]">
					<xsl:choose>
						<xsl:when test="following-sibling::page[1]/@id &gt; 0">
							<xsl:value-of select="following-sibling::page[1]/@id"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="number(0)"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="number(0)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="folpag" select="$folpagrtf"/>	

<!-- 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="course_css/universal.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="course_css/universal_contentstyle.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="course_css/{document(concat('sit_xml.php?id=', $parentsite))/site/course/@theme}.css" rel="stylesheet" media="screen" type="text/css"/>
				<link href="course_css/universal.css" rel="stylesheet" media="print" type="text/css"/>
				<xsl:if test="$import = 1 or $condensed = 1">
				<link href="course_css/embed.css" rel="stylesheet" media="screen" type="text/css"/>
				</xsl:if>
				<link href="course_css/universal_contentstyle.css" rel="stylesheet" media="print" type="text/css"/>
				<link href="course_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:if test="$homepage = $currentpage">
			<xsl:attribute name="id">home</xsl:attribute>
			</xsl:if>
				<div id="wrapper" class="clearfix">	
					<div id="ltcol">		
						<div id="logo" class="clearfix" style="padding-bottom: 0px !important; padding-bottom: 5px; ">				
							<img src="{document(concat('sit_xml.php?id=', $parentsite))/site/course/logo/@filename}" alt="Course Logo" id="course-logo"/>			
						</div>	
						<ul id="mainnav">
							<xsl:apply-templates select="document(concat('sit_xml.php?id=', $parentsite))/site/course/navigation/quicknav"/>
							<xsl:apply-templates select="document(concat('sit_xml.php?id=', $parentsite))/site/course/navigation/globalnav"/>
							<li class="mainnav"><a href="javascript:swap_menu('menu3')" rel="section"><img src="images/mainnav_s.gif" alt="-"/>Search</a></li>		
						</ul>
						<div class="search" style="display: none;" id="menu3">
							<form action="">
							<p><label for="search">Search by keyword:</label><br/>
							<input type="text" size="12" id="search"/> <a href="page.php?id={page/@id}"><input type="button" value="GO"/></a></p>
							</form>
						</div>
					</div>
					<div id="rtcol">
						
						<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 id="footer">	
							<p>	
								<img src="images/cte_logo.gif" alt="CTE"/>
								<xsl:text disable-output-escaping="yes">&lt;br/&gt;
								Web site created by:&lt;br/&gt;
								The Center for Technology in Education (CTE)&lt;br/&gt;
								Johns Hopkins University
								</xsl:text>
							</p>			
						</div>	
						
					</div>
				</div>
			</xsl:element>
		</html>
	</xsl:template>
	
</xsl:stylesheet>
