<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document SYSTEM "http://commons.omniupdate.com/dtd/standard.dtd"> 
<!-- 
Counties Home for UAEX 2013 Implementation

Based on UL lists, builds 3 select dropdowns for each county and also a list that alphabetizes all the counties, organized in 4 evenly populated columns

Contributors: Vinit Varghese, Caroline Spooner
Last Updated 7/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"/>

	<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">
				<h1><xsl:value-of select="$pageTitle"/></h1>
				
				 <div id="counties-list">
				 
		
				 
				 	<!-- get all the links from the district drop downs and sort them -->
					<xsl:variable name="vNodes">
						<xsl:for-each select="content/districts/ouc:div/ul/li[position() > 1]">
							<xsl:sort select=".//a/text()"/>
							<xsl:apply-templates select=".//a" mode="copy"/>
						</xsl:for-each>
					</xsl:variable>
				                 		       
				    <!-- number of columns -->
				    <xsl:variable name="vNumParts" select="4"/>
				    <!-- number of links in each column -->
				    <xsl:variable name="vNumCols" select="ceiling(count($vNodes/node()) div $vNumParts)"/>
				              <!-- for the amount of columns -->
				            <xsl:for-each select="$vNodes/a[position() mod $vNumCols = 1]">
				                <xsl:variable name="vCurPos" select="(position()-1)*$vNumCols +1"/>
				                <div class="col1">
				                	<!-- copy the links that belong in that column -->
				                    <xsl:for-each select="$vNodes/a[position() >= $vCurPos and not(position() > $vCurPos + $vNumCols -1)]">		                                
				                       <xsl:copy-of select="."/><br/>
				                    </xsl:for-each>
				                </div>
				            </xsl:for-each>		
					</div> <!--counties-list -->
		         
			        <div id="counties-map">
			          <xsl:apply-templates select="content/map/node()" mode="fs-img"/>
			         </div> <!--counties-map -->
			        
			    <div id="counties-dropdown">
			        <h1><xsl:value-of select="ou:pcfparam('districtsTitle')"/></h1>
			        <!-- counties-form -->
			        <form action="#" class="counties-form">
			        
			              <xsl:apply-templates select="content/districts/node()" mode="copy"/>
			              
			            <input class="hidden" type="submit" value="Submit" />
			        </form>
			        
			    </div>					
			</div>
		
		</div><!-- end container -->
		</div><!-- end main -->
	</xsl:template>
	
	<xsl:template match="districts/ouc:div//ul" mode="copy">
		<xsl:variable name="county-name" select="translate(string-join(li[1]//text()),' ','')"/><!-- remove spaces if there are any -->
		<fieldset>
			<legend class="hidden"><xsl:value-of select="$county-name"/> Counties</legend>
			<div class="select-holder">
				<label class="hidden" for="{lower-case($county-name)}-counties"><xsl:value-of select="$county-name"/> Counties</label>
				<select id="{lower-case($county-name)}-counties" class="newsletter">
				
					<option value="" selected=""><xsl:value-of select="$county-name"/></option>			
						
					<xsl:for-each select="li[position()>1]">
					<xsl:sort select="string-join(.//text())"/>
						<option value="{.//a[1]/@href}"><xsl:value-of select=".//text()"/></option>
					</xsl:for-each>
				
				</select>
			</div>
		</fieldset>
	</xsl:template>
	
			
	<xsl:template name="common-headcode">
		<xsl:copy-of select="ou:standardInclude('/_resources/includes/headcode.inc')"/>
		<!-- search for any instances of LDP forms or galleries -->
			<xsl:if test="/*:document/content//gallery">
				<xsl:comment>CSS and JS for OU Galleries</xsl:comment>
				<xsl:copy-of select="ou:gallery-headcode($galleryType)" />
			</xsl:if>
			<!-- <xsl:if test="/*:document/content//ouform">
				<xsl:comment>CSS and JS for OU Forms</xsl:comment>
				<link type="text/css" href="/_resources/css/ouforms-bootstrap.css" rel="stylesheet"/>
				<link type="text/css" href="/_resources/css/error-success.css" rel="stylesheet"/>
			</xsl:if> -->
		<xsl:if test="$ou:action!='pub'">
			<link type="text/css" href="/_resources/css/oustaging.css" rel="stylesheet"/>
			<script type="text/javascript">
			var $currentPage = "<xsl:value-of select="concat($domain,$ou:path)"/>";
			var $accessKey = "<xsl:value-of select="$ou:accessKey"/>";
			</script>
		</xsl:if>
		<!-- DirectEdit -->
		<xsl:if test="$ou:action='pub'">
				<script type="text/javascript" src="/_resources/js/directedit.js"></script>
				<script type="text/javascript">
				<xsl:comment><![CDATA[
				window.onload = function(){ directedit(); }
				]]>//</xsl:comment>
				</script>
				<script type="text/javascript">
				var $accessKey = "<xsl:value-of select="$ou:accessKey"/>";
				</script>
		</xsl:if>
		
		<script type="text/javascript" src="/_resources/js/county-map.js"></script>

	</xsl:template>


	

</xsl:stylesheet>
