<?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:variable name="type"><xsl:value-of select="name(document(concat('res_xml.php?id=', $childsite ))/resource/*[8])"/></xsl:variable>
	
<!-- LO PAGE -->
	
	<xsl:template match="resource">
		<div xmlns="http://www.w3.org/1999/xhtml" class="component">
			<h3><xsl:value-of select="/resource/name"/></h3>
			<h4><a href="page.php?id={$currentpage}">&lt; Back to <xsl:value-of select="document(concat('pag_xml.php?id=', $currentpage))/page/name"/></a></h4>
		</div>
		<div xmlns="http://www.w3.org/1999/xhtml" id="lo-details">
		<xsl:apply-templates select="document"/>
		<xsl:apply-templates select="link"/>
		<xsl:apply-templates select="image"/>
		<xsl:apply-templates select="flash"/>
		<xsl:apply-templates select="movie"/>
		<xsl:apply-templates select="sound"/>
		<xsl:apply-templates select="article"/>
						
		</div>		
	</xsl:template>
	
	<xsl:template match="document">	
		<xsl:call-template name="resourceitem"/>
	</xsl:template>
	
	<xsl:template match="link">	
		<xsl:call-template name="resourceitem"/>
	</xsl:template>
	
	<xsl:template match="article">		
		<div xmlns="http://www.w3.org/1999/xhtml" class="component">			
			<xsl:value-of select="body"/>
		</div>
		<xsl:call-template name="resourceitem"/>
	</xsl:template>
	
	<xsl:template match="image">	
		<div xmlns="http://www.w3.org/1999/xhtml" class="component">			
			<img src="../data/resource/{/resource/@id}/{file/filename}" alt="{/resource/name}" class="galdet"/>
		</div>
		<xsl:call-template name="resourceitem"/>
	</xsl:template>
	
	<xsl:template match="flash">	
		<xsl:param name="width">
			<xsl:choose>
			<xsl:when test="file/width &gt; 750">
				<xsl:value-of select="number(file/width)*.5"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="file/width"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:param>
		<xsl:param name="height">
			<xsl:choose>
			<xsl:when test="file/width &gt; 750">
				<xsl:value-of select="number(file/height)*.5"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="file/height"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:param>
		<div xmlns="http://www.w3.org/1999/xhtml" class="component">			
			<embed src="../data/resource/{/resource/@id}/{file/filename}" autoplay="true" width="{$width}" height="{$height}" controller="true" style="background-color:#FFFFFF;"></embed>
		</div>
		<xsl:call-template name="resourceitem"/>
	</xsl:template>
	
	<xsl:template match="movie">	
		<div xmlns="http://www.w3.org/1999/xhtml" class="component">		
			<embed src="../data/resource/{/resource/@id}/{hires/filename}" autoplay="true" controller="true" style="background-color:#FFFFFF;"></embed>
		</div>
		<xsl:call-template name="resourceitem"/>
	</xsl:template>
	
	<xsl:template match="sound">	
		<div xmlns="http://www.w3.org/1999/xhtml" class="component">			
			<embed src="../data/resource/{/resource/@id}/{file/filename}" autoplay="true" controller="true" style="background-color:#FFFFFF;"></embed>
		</div>
		<xsl:call-template name="resourceitem"/>
	</xsl:template>
	
	<xsl:template name="resourceitem">			
			<xsl:param name="filename">
			
			<xsl:choose>
				<xsl:when test="$type = 'movie'">
					<xsl:choose>
						<xsl:when test="lowres/filename/text()">
							<xsl:value-of select="lowres/filename"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="hires/filename"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="file/filename"/>
				</xsl:otherwise>
			</xsl:choose>
			
			</xsl:param>			
			<xsl:param name="iconname"><xsl:value-of select="substring-after($filename,'.')"/></xsl:param>
			<xsl:param name="icon"><xsl:value-of select="translate($iconname, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/></xsl:param>
		
			<div xmlns="http://www.w3.org/1999/xhtml" class="component">
				<div class="vcallout">
                        <div class="callout sum">
                          <h4 class="call"><span class="tab">Download</span></h4>
                           <div class="callshell">
                              <table class="complist">
                                 <tr>
                                    <td>
                                       	<h4><img src="images/icon_{$icon}.gif" class="icon left" alt="-"/> <xsl:value-of select="/resource/name"/></h4>                                       	
										<div>
											<xsl:choose>
											<xsl:when test="name() = 'link'">
											<p class="long">Go to: <a href="{url}"><xsl:value-of select="url"/></a></p>
											</xsl:when>
											<xsl:otherwise>
											<p>Download: <a href="../data/resource/{/resource/@id}/{file/filename}"><xsl:value-of select="file/filename"/></a> (<xsl:value-of select="/resource/*/file/size"/>)</p>
											</xsl:otherwise>
											</xsl:choose>
										</div>
                                    </td>
                                 </tr>								 
								 <xsl:if test="$icon = 'wmv'">
								 <tr>
								 	<td>									
										<div>
											<a href="http://www.microsoft.com/windows/windowsmedia/player/download/download.aspx"><img src="images/plug_wmv.gif" alt="Windows Media Plugin" style="float: none; margin-bottom: 6px;"/></a><br/>Having trouble viewing the movie?<br/><a href="http://www.microsoft.com/windows/windowsmedia/player/download/download.aspx">Download windows media player</a>
										</div>
									</td>
								 </tr>
								 </xsl:if>
								 
								 <xsl:if test="$icon = 'pdf'">
								 <tr>
								 	<td>									
										<div>
											<a href="http://www.adobe.com/products/acrobat/readstep2.html"><img src="images/plug_pdf.gif" alt="Adobe Acrobat Reader" style="float: none; margin-bottom: 6px;"/></a><br/>Having trouble viewing the pdf?<br/><a href="http://www.adobe.com/products/acrobat/readstep2.html">Download Adobe Acrobat Reader</a>
										</div>
									</td>
								 </tr>
								 </xsl:if>		
								 
								 <xsl:if test="$icon = 'swf'">
								 <tr>
								 	<td>									
										<div>
											<a href="http://sdc.shockwave.com/shockwave/download/download.cgi?"><img src="images/plug_swf.gif" alt="Macromedia Flash" style="float: none; margin-bottom: 6px;"/></a><br/>Having trouble viewing the Flash movie?<br/><a href="http://sdc.shockwave.com/shockwave/download/download.cgi?">Download the Macromedia Flash Player</a>
										</div>
									</td>
								 </tr>
								 </xsl:if>	
								 
								 <xsl:if test="$icon = 'mov'">
								 <tr>
								 	<td>									
										<div>
											<a href="http://www.apple.com/quicktime/download/win.html"><img src="images/plug_mov.gif" alt="Quicktime" style="float: none; margin-bottom: 6px;"/></a><br/>Having trouble viewing the movie?<br/><a href="http://www.apple.com/quicktime/download/win.html">Download the Quicktime Player</a>
										</div>
									</td>
								 </tr>
								 </xsl:if>	
								 
								 <xsl:if test="$icon = 'mp3'">
								 <tr>
								 	<td>									
										<div>
											<a href="http://www.apple.com/quicktime/download/win.html"><img src="images/plug_mov.gif" alt="Quicktime" style="float: none; margin-bottom: 6px;"/></a><br/>Having trouble listening to the MP3?<br/><a href="http://www.apple.com/quicktime/download/win.html">Download the Quicktime Player</a>
										</div>
									</td>
								 </tr>
								 </xsl:if>										 						 
								 
                              </table>
                              <hr class="on" />
                           </div>
                        </div>                        
                     </div>
				<xsl:if test="$type != 'article'"><p><xsl:value-of select="/resource/description" disable-output-escaping="yes"/></p></xsl:if>
				<hr class="on"></hr>
			</div>
	</xsl:template>
	
</xsl:stylesheet>

