<?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/" 
	xmlns:media="http://search.yahoo.com/mrss/" 
    exclude-result-prefixes="xs ou fn ouc content dc media">
	<!--
	Asset Transformations

	Special templates asset transformations
	
	Contributors: Caroline Spooner
	Last Updated 7/24/2013
	--> 
    
     <xsl:output encoding="UTF-8" />
     
     <xsl:template match="calendar" mode="copy">
		<xsl:choose>
			<!-- passes test and not publishing the file (preview/edit/compare) -->
			<xsl:when test="$ou:action != 'pub' and doc-available($bedeworkXML)">	    
				<ul class="event-list">
				 	
					<xsl:variable name="events" select="document($bedeworkXML)/bedework/events"/>     		
					<xsl:variable name="county" select="normalize-space($ou:bedeworkCounty)"/>
						     		    		
					<xsl:choose>
				 		<xsl:when test="contains($pageType,'counties') and string-length($county)>0">	     		
				 			<xsl:variable name="matches">
				 				<xsl:for-each select="$events/event">
				     				<xsl:if test="contains(string-join(categories/category/value/text()),$county)">
				     					<xsl:copy-of select="."/>
				     				</xsl:if>
				 				</xsl:for-each>
				 			</xsl:variable>	
				 			<xsl:for-each select="$matches/event[position()&lt;4]">
								<xsl:copy-of select="ou:bedework(.)"/>
							</xsl:for-each>
				 		</xsl:when>
						<xsl:otherwise>
							<xsl:for-each select="$events/event[position()&lt;4]">
								<xsl:copy-of select="ou:bedework(.)"/>
							</xsl:for-each>
						</xsl:otherwise>
					</xsl:choose>	
					
					<xsl:if test="not($events/event)">
                       <li><p>There are no upcoming events to show. Please visit the <a href="http://calendar.uada.edu/cal/main/showMain.rdo">main calendar</a> to see all UAEX events.</p></li>
					</xsl:if>	
								
				</ul>
			</xsl:when>
			<!-- It didn't pass the doc-available test, but we are not publishing the file -->
			<xsl:when test="$ou:action!='pub'">
				<p class="omniupdate message error"><strong>System Message</strong><br/>Please check that the Bedework XML URL (<xsl:value-of select="$bedeworkXML"/>) is valid.</p>
			</xsl:when>
			<!-- We are publishing the file, so no need to test the file b/c different method is used to display -->
			<xsl:otherwise>
				<xsl:variable name="id" select="concat('feed','-',ou:hrefToID($bedeworkXML))"/>
					

					
					<div id="{$id}">
					                       

					<!-- rss goes here -->
				<script type="text/javascript">
$(document).ready(function() {

// properties
var props = {
  feed: "<xsl:value-of select="$bedeworkXML"/>",
  county: "<xsl:value-of select="$ou:bedeworkCounty"/>"                                    
};                 
                      
var params_to_send = { 
   feed: props.feed, county: props.county
};

$.ajax({
url : "/_resources/wnl/bedework.ashx",	
data: params_to_send,
success: function(data){    
	$('#<xsl:value-of select="$id"/>').before(data);
	if ($('em.date').length == 0) {
	$('#<xsl:value-of select="$id"/>').before('&lt;ul class="event-list no-events"&gt;&lt;li&gt;&lt;p&gt;There are no upcoming events to show. Please visit the &lt;a href="http://calendar.uada.edu/cal/main/showMain.rdo"&gt;main calendar&lt;/a&gt; to see all UAEX events.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;');
	}
	
}
});

});			
				</script>
				<noscript>
					<ul class="event-list no-events"><li><p>Please visit the <a href="http://calendar.uada.edu/cal/main/showMain.rdo">main calendar</a> to see all UAEX events.</p></li></ul>
				</noscript></div>			
			</xsl:otherwise>
     		</xsl:choose>
     	</xsl:template>
     	
        <xsl:function name="ou:bedework">
		<xsl:param name="event"/>
		<li>
			<em class="date"><span><xsl:value-of select="upper-case(ou:getShortMonth($event/start/monthname))"/></span><xsl:value-of select="$event/start/day"/></em>
			<p><a href="http://calendar.uada.edu/cal/event/eventView.do?b=de&amp;calPath={$event/calendar/path}&amp;guid={$event/guid}&amp;recurrenceId={$event/recurrenceId}"><xsl:value-of select="$event/summary"/></a></p>
		</li>	
		</xsl:function>
		
		<xsl:template match="news" mode="copy">
		<xsl:variable name="type" select="@type"/>
		
		<xsl:variable name="feed" select="string(@feed)"/>
		<!-- xml feed in asset. concat to domain if rel is internal -->
		<xsl:variable name="assetXml" select="if (@source!='external') then(concat($domain,@feed)) else (@feed)"/>
		<!-- use ou:feed if no xml feed was specified in the asset -->
		<xsl:variable name="xml" select="if(string-length(@feed)>0) then($assetXml) else(concat($domain,$ou:feed))"/>			
		<!-- number of items displayed by the asset -->
		<xsl:variable name="max" select="if(string-length(@items)>0) then(@items) else(100)"/>
		
		<!-- if rss feed exists -->
			<xsl:if test="doc-available($xml)">	

			<!-- save to a variable to reduce doc-calls-->
			<xsl:variable name="rss" select="document($xml)"/>
				
			<xsl:choose>
				
				<!-- use xsl to display items on edit/preview -->
				<!-- the for-each is inside each when so that the method is only evaluated once, before the loop starts. -->
				<xsl:when test="$ou:action!='pub'">				

					<xsl:choose>
						
						<xsl:when test="@type='news-list'">		

							<ul class="news-list">
								<xsl:for-each select="$rss/rss/channel/item[position()&lt;=$max]">				
									<xsl:copy-of select="ou:rss-news-list(.)"/>
								</xsl:for-each>	
							</ul>
							
						</xsl:when>
										
						
						<xsl:when test="@type='counties-home-article'">							
							<xsl:for-each select="$rss/rss/channel/item[position()&lt;=$max]">				
								<div class="news-area">
									<xsl:if test="media:content[position()=last()]/@url">
										<div class="photo">
												<a href="{link}">
													<img src="{media:content[position()=last()]/@url}" width="123" alt="{media:content[position()=last()]/media:description}"/>
												</a>																							
										</div>
									</xsl:if>
									<h3><a href="{link}"><xsl:value-of select="title"/></a></h3>										
									
									<xsl:call-template name="rss-content"/>	
									
									<xsl:if test="media:content[position()=last()]/media:description">				
										<p><em>Photo: <xsl:value-of select="media:content[position()=last()]/media:description"/></em></p>					
									</xsl:if>
								</div>	
							</xsl:for-each>	
							
						</xsl:when>
						
						<xsl:when test="@type='counties-program-article'">
						
						<xsl:for-each select="$rss/rss/channel/item[position()&lt;=$max]">
				
							<article class="content-article">
								<xsl:if test="media:content[position()=last()]/@url">
									<div class="photo" >
										<a href="{link}">
											<img src="{media:content[position()=last()]/@url}" width="123" alt="{media:content[position()=last()]/media:description}"/>
										</a>
									</div>
								</xsl:if>
								<h3><a href="{link}"><xsl:value-of select="title"/></a></h3>										
								
								<xsl:call-template name="rss-content"/>	
								
								<xsl:if test="media:content[position()=last()]/media:description">				
									<p><em>Photo: <xsl:value-of select="media:content[position()=last()]/media:description"/></em></p>					
								</xsl:if>
							</article>	
						</xsl:for-each>	
						
						</xsl:when>
						
						<xsl:when test="@type='uaex-home-article'">
						
						<xsl:for-each select="$rss/rss/channel/item[1]">			
												
							<article class="article g1">
								<xsl:if test="media:content">
									<div class="photo">
										<a href="{link}">
											<img src="{media:content[position()=last()]/@url}" width="104" alt="{media:content[position()=last()]/media:description}"/>
										</a>
									</div>
								</xsl:if>
								<div class="description">
									<h1><a href="{link}"><xsl:value-of select="title"/></a></h1>	
									
									<xsl:call-template name="rss-content"/>	
									
									<a href="{link}" class="link">Learn More</a>
								</div>														
							</article>	
							
						</xsl:for-each>	
						
						</xsl:when>
						
					<xsl:when test="@type='interior-article'">
						
						<xsl:for-each select="$rss/rss/channel/item[position()&lt;=$max]">			
												
							<article>
							<div class="description">						
									<h2><a href="{link}"><xsl:value-of select="title"/></a></h2>										
									<xsl:call-template name="rss-content"/>	
									<br/>
									<a href="{link}" class="link">Learn More</a>									
									</div><br/>
							</article>	
							
						</xsl:for-each>	
						
						</xsl:when>
						
					<xsl:when test="@type='interior-article-nolink'">
						
						<xsl:for-each select="$rss/rss/channel/item[position()&lt;=$max]">			
												
							<article>
							<div class="description">						
									<h2><a href="{link}"><xsl:value-of select="title"/></a></h2>										
									<xsl:call-template name="rss-content"/>										
									</div><br/>
							</article>	
							
						</xsl:for-each>	
						
						</xsl:when>


					
					</xsl:choose>
										
				</xsl:when>
				
				<!-- use C# to display items dynamically on published page -->
				<xsl:otherwise>
				<xsl:variable name="id" select="concat($type,'-',ou:hrefToID($xml))"/>
					<div id="{$id}"><!-- rss goes here -->
<script type="text/javascript">
$(document).ready(function() {

// properties
var props = {
  type: "<xsl:value-of select="$type"/>",
  feed: "<xsl:value-of select="if(string-length($feed)>0) then($feed) else($ou:feed)"/>",                                    
  numberToDisplay: <xsl:value-of select="$max"/>
};                 
                      
                      
var params_to_send = { 
   type: props.type, feed: props.feed, numberToDisplay: props.numberToDisplay
};

$.ajax({
url : "/_resources/wnl/rss.ashx",	
data: params_to_send,
success: function(data){    
	$('#<xsl:value-of select="$id"/>').before(data);
	$('#<xsl:value-of select="$id"/>').remove();
	
}
});

});			
</script></div>				
				</xsl:otherwise>
				
			</xsl:choose>	

			
		</xsl:if>
		
	</xsl:template>
	
	<!-- context node is an rss item -->
	<xsl:template name="rss-content">
		<xsl:choose>
			<xsl:when test="ouc:content">
				<xsl:apply-templates select="ouc:content/node()" mode="copy"/>
			</xsl:when>
			<xsl:when test="content:encoded">
				<xsl:variable name="hold-text">
					<xsl:value-of select="content:encoded/node()" disable-output-escaping="yes"/>
				</xsl:variable>
				<xsl:value-of select="description" disable-output-escaping="yes"/><br/>
			</xsl:when>
			<xsl:otherwise>
				<p><xsl:value-of select="description"/></p>	
			</xsl:otherwise>
		</xsl:choose>				
	</xsl:template>


	
	<xsl:function name="ou:rss-content-article">
	<xsl:param name="item"/>
	<xsl:param name="item-image"/>
	<!-- display an LI element with a link to the item -->								
		
	</xsl:function>
	
	<xsl:function name="ou:rss-news-list">
	<xsl:param name="item"/>	
		<li>
			<a href="{$item/link}"><xsl:value-of select="$item/title"/></a>
		</li>	
	</xsl:function>
     
    
	


<!-- END ACCORDION -->

</xsl:stylesheet>
