<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document SYSTEM "http://commons.omniupdate.com/dtd/standard.dtd"> 
<!-- 
County Home Page and County Programs Page

Contributors:  Caroline Spooner
Last Updated 10/16/2013
-->
<xsl:stylesheet version="3.0" 
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:xs="http://www.w3.org/2001/XMLSchema" 
				xmlns:ou="http://omniupdate.com/XSL/Variables"
				xmlns:fn="http://omniupdate.com/XSL/Functions" 
				xmlns:ouc="http://omniupdate.com/XSL/Variables"
				exclude-result-prefixes="ou xsl xs fn ouc">
	
<xsl:import href="common.xsl"/>


<!-- determine if county data include is a pcf or an inc file -->
<xsl:variable name="originalDataPath" select="ou:pcfparam('dataPath')"/>
<xsl:variable name="dataPath" select="if($ou:action='pub') then($originalDataPath) else( concat($ou:root,$ou:site,substring-before($originalDataPath,'.inc'),'.pcf')  )"/>

	<xsl:template name="page-content">
	
		<xsl:comment> main </xsl:comment>
		<div id="main">

			<xsl:comment> container</xsl:comment>		
			<div class="container">
			
				<xsl:comment> breadcrumbs </xsl:comment>			
				<xsl:call-template name="breadcrumb">
					<xsl:with-param name="path" select="$ou:dirname"/>								
				</xsl:call-template>
								
				<div id="two-columns" class="g3">
							
				<xsl:choose> 
					<xsl:when test="$pageType='counties_programs'">					
						<!-- BEGIN LEFT COLUMN -->
							<xsl:call-template name="leftcolumn"/>
						<!-- END LEFT COLUMN -->					
						<!-- BEGIN CONTENT -->					
							<div id="content">						
								<xsl:apply-templates select="content/maincontent" mode="copy"/>							
							</div>						
						<!-- END CONTENT -->					
					</xsl:when>
					<xsl:otherwise>
						<div class="main-columns">						
							<!-- BEGIN LEFT COLUMN -->
								<xsl:call-template name="leftcolumn"/>
							<!-- END LEFT COLUMN -->							
							<!-- BEGIN CONTENT -->					
								<div id="content">						
									<xsl:apply-templates select="content/maincontent" mode="copy"/>							
								</div>						
							<!-- END CONTENT -->						
						</div> <!-- end main columns -->
					</xsl:otherwise>
				</xsl:choose>
				
					
				<xsl:if test="$pageType='counties_home'">
					<!-- BEGIN RIGHT COLUMN -->								
					<xsl:comment> lists-block </xsl:comment>
					<aside class="lists-block">		
						<nav>				
							<xsl:apply-templates select="content/events/node()" mode="copy"/>	
						</nav>			
						<nav class="item-list">
							<xsl:apply-templates select="content/resources/node()" mode="copy"/>				
						</nav>
						<nav class="item-list">
							<xsl:apply-templates select="content/programs/node()" mode="copy"/>		
						</nav>																																			
					</aside>					
					<!-- END RIGHT COLUMN -->
				</xsl:if>
				
				</div><!-- end two columns -->
				
				<div class="cf"><!--clearfix--></div>	
												
			</div><!-- end container -->
		</div><!-- end main -->

	</xsl:template>
	
	<!-- BEGIN SPECIAL MATCH #1 MAINCONTENT -->
	<!-- if any special options are activated for copying misc content, they are applied in this match -->
	<xsl:template match="maincontent" mode="copy">	
		
		<!--
		<xsl:if test="$ou:action = 'edt'">
			<div class="omniupdate message success">
			<p>
			The following groups are in place for the editable regions below. To configure user groups for a new page, a level 10 Admin may set each region to a different group via Directory Variable.
			To configure user groups for an already existing page (<em>such as this one</em>), the group attribute for each editable area may be changed by any user with Source Code access. 
			</p>
			<p><em>Additionally, the first group is the default access group on new pages for all other editable regions and page properties.</em></p>
			<ol>
				<xsl:for-each select="ouc:div">
					<li style="list-style-position:inside;"><xsl:value-of select="@group"/></li>
				</xsl:for-each>
			</ol>
			</div>
		</xsl:if>
		-->		

		<xsl:choose>
			<xsl:when test="$pageType='counties_home'">
				<xsl:apply-templates select="ouc:div[1]" mode="copy"/> <!-- copy everything normally -->	
				<div class="news-holder">
					<xsl:apply-templates select="ouc:div[position()>1]" mode="copy" /> <!-- copy everything normally -->	
					<xsl:apply-templates select="/*:document/content/bottomcontent/node()" mode="copy"/>	<!-- additional bottom content -->			
				</div>	
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates mode="copy"/> <!-- copy everything normally -->	
				<xsl:apply-templates select="/*:document/content/bottomcontent/node()" mode="copy"/>	<!-- additional bottom content -->				
			</xsl:otherwise>
		</xsl:choose>
		
						
	</xsl:template>
	<!-- END SPECIAL MATCH #1 MAINCONTENT -->
	
	<xsl:template name="leftcolumn">
	<xsl:comment> sidebar </xsl:comment>			
	<aside id="sidebar">															
		<section class="address-block">
		<xsl:variable name="backup" select="concat($ou:root,$ou:site,$ou:dirname,'/_leftcolumn.pcf')"/>
			<xsl:choose>
			
				<!-- if we are not using include content -->
				<xsl:when test="ou:pcfparam('useInclude')='editable'">							
					<div class="address-holder">
						<xsl:apply-templates select="content/contact/node()" mode="copy"/>	
					</div>
					<div class="map-block">			
						<xsl:apply-templates select="content/county/node()" mode="js-img"/>	<!-- javascript optimized image -->
					</div>																				
				</xsl:when>
				
				<!-- if publishing use virtual include -->	
				<xsl:when test="$ou:action='pub'">
					<xsl:copy-of select="ou:standardInclude($dataPath)"/>
				</xsl:when>
				
				<!-- in most cases, data path will be pcf file on staging. -->
				<xsl:when test="doc-available($dataPath)">
					<xsl:variable name="doc" select="document($dataPath)/*:document"/>
					<xsl:apply-templates select="$doc/contact/ouc:div/node()" mode="copy"/>
					<xsl:apply-templates select="$doc/county/ouc:div/node()" mode="js-img"/>
					<xsl:if test="$doc//gallery">
						<xsl:copy-of select="ou:gallery-headcode($galleryType)" />
					</xsl:if>
				</xsl:when>
				
				<!-- if it turned out to not be a pcf file on stating -->
				<xsl:when test="unparsed-text-available(concat($ou:httproot,$originalDataPath))">
					<xsl:value-of select="unparsed-text(concat($ou:httproot,$originalDataPath))" disable-output-escaping="yes"/> <!-- don't escape html -->
				</xsl:when>
				
				<!-- try to see if the one created by the template is there -->
				 <xsl:when test="doc-available($backup)">
					<xsl:variable name="doc" select="document($backup)/*:document"/>
					<xsl:apply-templates select="$doc/contact/ouc:div/node()" mode="copy"/>
					<xsl:apply-templates select="$doc/county/ouc:div/node()" mode="js-img"/>
					<xsl:if test="$doc//gallery">
						<xsl:copy-of select="ou:gallery-headcode($galleryType)" />
					</xsl:if>
				</xsl:when>  
				
				<!-- everything we tried failed -->
				<xsl:when test="$ou:action='prv' or $ou:action='edt'">
				<p class="omniupdate message">System Warning:<br/>No include file was found for the left column contents.
				Please select Local Editable region for the Left Column Content option in page properties, 
				or make sure that the left column include file exists and is selected in the filechooser (_leftcolumn.pcf).</p>
				</xsl:when>
												
			</xsl:choose>	
		</section>																						
	</aside>
	</xsl:template>

	<!-- no more than 5 links under programs -->
	<xsl:template match="programs//ul" mode="copy">
	<ul>
		<xsl:apply-templates select="attribute()|li[position() &lt; 6]" mode="copy"/>
		<xsl:if test="li[6] and $ou:action!='pub'">
		<li><p class="omniupdate message error">System Message: Maximum number of links reached. Please enter no more than 5 links in this region.</p></li>
		</xsl:if>
	</ul>
	</xsl:template>

	

</xsl:stylesheet>
