<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "http://commons.omniupdate.com/dtd/standard.dtd"> 
<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"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/" 
    exclude-result-prefixes="xs ou fn ouc content dc">
	<!--
	SPECIAL TEMPLTES
	Special templates not specific to a particular page type
	
	Contents	
	5.Lightboxes
	4.Drop Navigation
	3.County Map Image
	2.WordPress Post
	1.Complex Accordion
	
	Contributors: Caroline Spooner
	Last Updated 7/16/2013
	--> 
    
     <xsl:output encoding="UTF-8" />

	<!-- 5. LIGHTBOXES -->
	
	<xsl:template name="lightboxes">
	<xsl:param name="content" select="content"/>
	
	<xsl:for-each select="$content//a[@class='open-lightbox']">
									
		<xsl:comment> lightbox </xsl:comment>					
		<!-- create div for lightbox content, id is generated automatically based on the original link -->
		<div class="lightbox" id="{ou:hrefToID(@href)}">
			<div class="lightbox-holder">							
				<div class="video-holder">
				<xsl:choose>				
					<!-- Link to a YouTube video (browser link) -->
					<xsl:when test="contains(@href,'watch?v=')">
						<iframe width="560" height="315" src="http://www.youtube.com/embed/{ou:hrefToYouTube(@href,'watch?v=','&amp;')}"  allowfullscreen="allowfullscreen"></iframe>
					</xsl:when>
					<!-- Link to a YouTube video (share link) -->
					<xsl:when test="contains(@href,'youtu.be')">	
						<iframe width="560" height="315" src="http://www.youtube.com/embed/{ou:hrefToYouTube(@href,'youtu.be/','?')}"  allowfullscreen="allowfullscreen"></iframe>
					</xsl:when>
					<!-- matches common image file extension -->
					<xsl:when test="contains(@href,'.jpg') or contains(@href,'.jpeg') or contains(@href,'.png') or contains(@href,'.PNG') or contains(@href,'.gif') or contains(@href,'.bmp') or contains(@href,'.tiff')">
						<img src="{@href}">
							<xsl:if test="img">
								<xsl:apply-templates select="img/attribute()[name()!='src' and name()!='width' and name()!='height']" mode="copy"/>
							</xsl:if>
						</img>
					</xsl:when>
					<!-- Link to an include file -->
					<xsl:when test="contains(@href,'.inc')">
						<xsl:variable name="content" select="if(contains(@href,'http')) then(@href) else(concat($domain,@href))"/>							
						<xsl:if test="unparsed-text-available($content)">
							<xsl:value-of select="unparsed-text($content)" disable-output-escaping="yes"/>
						</xsl:if>						
					</xsl:when>	
					<!-- Link to unknown type of web content (for example, if the user is already using the //www.youtube.com/embed/ path) -->
					<xsl:otherwise>
						<iframe width="560" height="315" src="{@href}"  allowfullscreen="allowfullscreen"></iframe>						
					</xsl:otherwise>
				</xsl:choose>	
					
				</div>
			</div>	
						
		</div>
												
	</xsl:for-each>
	
	</xsl:template>


	
     <!-- 4. DROP NAVIGATION -->
     
     <xsl:template name="drop-nav">
     <xsl:param name="key"/>    <!-- access key, to match with a link --> 
     <xsl:variable name="nav-path" select="concat($ou:root,$ou:site,'/_resources/includes/top-nav.pcf')"/> <!-- location of top navigation -->
     
     <xsl:if test="doc-available($nav-path)"> 
 	 <xsl:variable name="top-nav" select="document($nav-path)"/>
     	
     	<!-- search through the table transformation for a matching access key -->
     	<ul>
	    <xsl:for-each select="$top-nav/document//table[@class='topnav-table']">			     	
	    <xsl:if test="thead/tr/th/a[@accesskey = $key]">
	     		
			<xsl:for-each select="tbody/tr/td//a">
				<!-- copy links from the matching table -->
	 			<li><xsl:apply-templates select="." mode="copy"/></li>
	 			
			</xsl:for-each>
	     		
	    </xsl:if>		
	    </xsl:for-each>
     	</ul>
	     	
     </xsl:if>
     
     </xsl:template>
     
     <!-- 3. COUNTY MAP IMAGE -->
     
     <xsl:template name="countyMap">
     <xsl:param name="image"/>     
     <xsl:variable name="html"><img alt="{$pageTitle}" src="{$image}"/></xsl:variable>
     
     	<!-- send image through template match, in table-transformations2.xsl -->
     	<!-- apply special classes and no-script tag -->
   	 	<xsl:apply-templates select="$html" mode="js-img"/>
     
     </xsl:template>
		
	<!-- 2. WORDPRESS POST -->
	
	<!-- display content from an external wordpress blog -->
	<xsl:template name="WordPress">
	<xsl:param name="url" select="ou:pcfparam('postLink')"/>
	<xsl:variable name="getFirst" select="if(string-length(substring-after($url,'/')) &lt; 1) then('yes') else('no')"/>
	
	<!-- if no base URl was entered, try to guess what it could be. -->
	<xsl:variable name="guessBaseUrl">
		<xsl:choose>
			<xsl:when test="$getFirst='yes'">
				<xsl:value-of select="concat($url,'feed')"/>
			</xsl:when>
			<xsl:when test="string-length(ou:pcfparam('blogURL'))>0">
				<xsl:value-of select="ou:pcfparam('blogURL')"/>
			</xsl:when>
			<xsl:when test="contains($url,'?')">
				<xsl:value-of select="normalize-space(concat(substring-before($url,'?'), '?feed=rss'))"/>
			</xsl:when>
			<xsl:when test="not(contains($url,'http://'))">
				<xsl:value-of select="concat('http://',substring-before($url,'/'),'/feed')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat('http://',substring-before(substring-after($url,'http://'),'/'),'/feed')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
		
	<!-- display post contents, and error/success messages, if any -->	
	
		<xsl:choose>
		<xsl:when test="doc-available($guessBaseUrl)">
			<xsl:variable name="blog" select="document($guessBaseUrl)"/>		
			
			<xsl:variable name="postInfo" select="string-join(ou:pcfparam('postInfo'))"/>
		
				<xsl:for-each select="$blog/rss/channel/item/link[text()=normalize-space($url)]">		
			
						<xsl:if test="$ou:action='prv' or $ou:action='edt'">			
						<p class="omniupdate message success">URL "<xsl:value-of select="$url"/>" was found.</p>				
						</xsl:if>			
						
						<xsl:if test="contains($postInfo,'displayTitle')">
						<h1><xsl:value-of select="../title" disable-output-escaping="yes"/></h1>	
						</xsl:if>
						
						<p>
						<xsl:if test="contains($postInfo,'displayAuthor')">		
						by <xsl:value-of select="../dc:creator"/>
						</xsl:if>
						
						<xsl:if test="contains($postInfo,'displayTags') and ../category"> in
						<xsl:for-each select="../category">
							<xsl:value-of select="."/>
							<xsl:if test="position()!=last()">, </xsl:if>
						</xsl:for-each>
						</xsl:if>
						
						<xsl:if test="contains($postInfo,'displayDate')">
						<xsl:text> on </xsl:text><xsl:variable name="date" select="tokenize(../pubDate,' ')"/><xsl:value-of select="concat(ou:getWholeMonth($date[3]),' ',$date[2],', ',$date[4])"/>						
						</xsl:if>
						
						<xsl:if test="contains($postInfo,'displayLink')">
						<xsl:text> </xsl:text><a href="{.}">Permalink</a>
						</xsl:if>
						</p>	
										
						<xsl:value-of select="../content:encoded" disable-output-escaping="yes"/>	
									
					</xsl:for-each>							
	
			</xsl:when>
		
			<xsl:otherwise>
			<xsl:if test="$ou:action!='pub'">
				<p class="omniupdate message error">WordPress RSS Feed was not found. We guessed it was at "<xsl:value-of select="$guessBaseUrl"/>". Please try a different Post Link or XML Link, or disable WordPress Content.</p>
			</xsl:if>
		</xsl:otherwise>
	</xsl:choose>

	</xsl:template>
	

<!-- END WORDPRESS -->

<!-- 1. COMPLEX ACCORDION -->
<!-- NOTE: Simple accordion is defined in table-transformations2.xsl -->



<xsl:template name="accordion">

<xsl:if test="$ou:action='edt' or $ou:action='prv'">
	<p class="omniupdate message success">The Complex Accordion is displayed below based on table contents. Table information from all regions will be grouped together, in original order.</p>
</xsl:if>

	<ul class="tabset">	
	<xsl:for-each select="/*:document//table[@class='accordion-complex']">
	<xsl:variable name="tablePos" select="position()"/>	
		
		<li> <!--  (Table Caption) Year Listing -->
		<xsl:if test="$tablePos=1"><xsl:attribute name="class" select="'active'"/></xsl:if>
			<a href="#tab{$tablePos}">							
				<xsl:apply-templates select="caption/node()" mode="copy"/>				
			</a>
		</li>
		
	</xsl:for-each>		
	</ul>
	
	<div class="tab-content">
	<xsl:for-each select="/*:document//table[@class='accordion-complex']">

	<xsl:variable name="tablePos" select="position()"/>	
	
		<div id="tab{$tablePos}">
		
			<ul class="slide-list accordion">					
			<xsl:for-each select="tbody/tr">
			<xsl:variable name="nextPosition" select="number(position()) +1"/>
			<xsl:if test="position() mod 2 = 1">
				
				<li><xsl:if test="position()=1"><xsl:attribute name="class" select="'active'"/></xsl:if>
					<!-- table contents (even row) Month Name -->
					<a href="#" class="opener"><xsl:apply-templates select="td[1]/node()" mode="copy"/></a>
					<div class="slide">
						<!-- table contents (odd row) News Items in Month -->
						<xsl:apply-templates select="./../tr[$nextPosition]/td[1]/node()" mode="copy"/>
					</div>
				</li>
				
			</xsl:if>
			</xsl:for-each>
						
			</ul>
		
		</div>		
		
	</xsl:for-each>
	</div>
	
</xsl:template>

<!-- END ACCORDION -->

</xsl:stylesheet>
