<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" omit-xml-declaration="yes"/>

	<!-- Detail Templates -->
	<!-- These templates are used to grep additional infos of the movies/tv shows -->

	<xsl:template name="video-codec">
		<xsl:choose>
			<xsl:when test="contains(videoCodec,'AVC') or contains(videoCodec,'avc1')"><img src="pictures/thumb-H264.png"/></xsl:when>
			<xsl:when test="contains(videoCodec,'XviD')"><img src="pictures/thumb-XviD.png"/></xsl:when>
			<xsl:when test="contains(videoCodec,'DivX')"><img src="pictures/thumb-DivX.png"/></xsl:when>
			<xsl:when test="contains(videoCodec,'MPEG')"><img src="pictures/thumb-MPEG.png"/></xsl:when>
			<xsl:when test="contains(videoCodec,'microsoft')"><img src="pictures/thumb-MS.png"/></xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="videoCodec" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="video-source">
		<xsl:choose>
			<xsl:when test="contains(videoSource,'BluRay') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'m2ts') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'bluray')"><img src="pictures/thumb-Blu-ray.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'HDDVD') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'hddvd')"><img src="pictures/thumb-HDDVD.png"/></xsl:when>
		  <xsl:when test="contains(videoSource,'HDTV') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'hdtv')"><img src="pictures/thumb-HDTV.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'CAM') or contains(/details/movie/files/file/fileURL,'CAM')"><img src="pictures/thumb-CAM.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'TS') and not(contains(translate(videoSource,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'video_ts')) or contains(/details/movie/files/file/fileURL,'.TS.') and not(contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'video_ts')) or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'.telesync.')"><img src="pictures/thumb-Telecine.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'DVDRip') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'dvdrip')"><img src="pictures/thumb-DVD.png"/></xsl:when>
 			<xsl:when test="contains(videoSource,'SATRip') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'satrip')"><img src="pictures/thumb-DVB-S.png"/></xsl:when>
     	<xsl:when test="contains(videoSource,'DVD') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'dvdr') or contains(/details/movie/files/file/fileURL,'.img')"><img src="pictures/thumb-DVD.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'UNKNOWN')">Unknown</xsl:when>
			<xsl:when test="not(string(videoSource))">&#160;</xsl:when>
   		<xsl:otherwise>
    		<xsl:value-of select="videoSource" />
   		</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template name="video-source-start">
		<xsl:choose>
			<xsl:when test="contains(videoSource,'BluRay') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'m2ts') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'bluray')"><img src="pictures/th_blueray.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'HDDVD') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'hddvd')"><img src="pictures/thumb-HDDVD.png"/></xsl:when>
		  <xsl:when test="contains(videoSource,'HDTV') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'hdtv')"><img src="pictures/thumb-HDTV.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'CAM') or contains(/details/movie/files/file/fileURL,'CAM')"><img src="pictures/thumb-CAM.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'TS') and not(contains(translate(videoSource,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'video_ts')) or contains(/details/movie/files/file/fileURL,'.TS.') and not(contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'video_ts'))"><img src="pictures/thumb-Telecine.png"/></xsl:when>
			<xsl:when test="contains(videoSource,'DVDRip') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'dvdrip')"><img src="pictures/th_dvd.png"/></xsl:when>
 			<xsl:when test="contains(videoSource,'SATRip') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'satrip')"><img src="pictures/thumb-DVB-S.png"/></xsl:when>
     	<xsl:when test="contains(videoSource,'DVD') or contains(translate(/details/movie/files/file/fileURL,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'dvdr') or contains(/details/movie/files/file/fileURL,'.img')"><img src="pictures/th_dvd.png"/></xsl:when>
     	<xsl:otherwise>&#160;</xsl:otherwise>
		</xsl:choose>
	</xsl:template>



	<xsl:template name="template-videoOutput">
		<xsl:choose>
			<xsl:when test="contains(videoOutput,'1080p')"><img src="pictures/thumb-fullHd.png"/>&#160;<xsl:value-of select="fps" />Hz</xsl:when>
			<xsl:when test="contains(videoOutput,'720p')"><img src="pictures/thumb-halfHd.gif"/>&#160;<xsl:value-of select="fps" />Hz</xsl:when>
			<xsl:otherwise>
				<img src="pictures/thumb-SDTV.png"/>&#160;<xsl:value-of select="fps" />Hz
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="videoOutput-start">
		<xsl:choose>
			<xsl:when test="contains(videoOutput,'1080p')"><img src="pictures/th_full_hd.png"/></xsl:when>
			<xsl:when test="contains(videoOutput,'720p')"><img src="pictures/th_half_hd.png"/></xsl:when>
			<xsl:otherwise>
				<img src="pictures/th_sd_tv.png"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template name="audio-codec">
		<xsl:variable name="parsedAudioCodec" select="tokenize(//details/movie/audioCodec,' / ')"/>
		<xsl:variable name="parsedAudioChannels" select="tokenize(//details/movie/audioChannels,' / ')"/>
		<xsl:for-each select="$parsedAudioCodec">
		  <xsl:if test="position() &lt; 5">
  			<xsl:variable name="pass" select="position()" />
  			<xsl:if test="$pass!=1"> | </xsl:if>
  			<!--
  			<xsl:choose>
  				<xsl:when test="contains($parsedAudioCodec[$pass],'AC3') or contains($parsedAudioCodec[$pass],'DTS') or contains($parsedAudioCodec[$pass],'MP3') or contains($parsedAudioCodec[$pass],'AAC') or contains($parsedAudioCodec[$pass],'TrueHD') or contains($parsedAudioCodec[$pass],'VORBIS') or contains($parsedAudioCodec[$pass],'orbis') or contains($parsedAudioCodec[$pass],'A_FLAC') or contains($parsedAudioCodec[$pass],'QDM') or contains($parsedAudioCodec[$pass],'microsoft')">
  					<xsl:if test="contains($parsedAudioCodec[$pass],'AC3')" ><img src="pictures/thumb-dolbydigital.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'TrueHD')" ><img src="pictures/thumb-TrueHD.png" align="top"/></xsl:if>
  					<xsl:choose>
  						<xsl:when test="contains($parsedAudioCodec[$pass],'DTS-HD')"><img src="pictures/thumb-DTSHD.png" align="top"/></xsl:when>
  						<xsl:otherwise><xsl:if test="contains($parsedAudioCodec[$pass],'DTS')"><img src="pictures/thumb-digital-dts-surround.png" align="top"/></xsl:if></xsl:otherwise>
  					</xsl:choose>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'MP3')"><img src="pictures/thumb-MP3.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'AAC')"><img src="pictures/thumb-AAC.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'VORBIS') or contains($parsedAudioCodec[$pass],'orbis')"><img src="pictures/thumb-Ogg.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'A_FLAC')"><img src="pictures/thumb-flac.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'QDM2') or contains($parsedAudioCodec[$pass],'QDMC')"><img src="pictures/thumb-Q.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'microsoft')"><img src="pictures/thumb-MS.png" align="top"/></xsl:if>
  				</xsl:when>
  				<xsl:otherwise>
  					<xsl:value-of select="$parsedAudioCodec[$pass]" />
  				</xsl:otherwise>
  			</xsl:choose>
  			-->
  			<xsl:value-of select="$parsedAudioCodec[$pass]" />&#160;
  			<xsl:choose>
  				<xsl:when test="$parsedAudioChannels[$pass]=6">
  					<xsl:text>5.1</xsl:text>
  				</xsl:when>
  		 		<xsl:when test="$parsedAudioChannels[$pass]=8">
  			  	<xsl:text>7.1</xsl:text>
  		 		</xsl:when>
  	   		<xsl:when test="$parsedAudioChannels[$pass]=2">
  	    		<xsl:text>2.0</xsl:text>
  	   		</xsl:when>
  				<xsl:when test="$parsedAudioChannels[$pass]=3">
  					<xsl:text>2.1</xsl:text>
  				</xsl:when>
  				<xsl:otherwise>
  					<xsl:value-of select="$parsedAudioChannels[$pass]" />
  				</xsl:otherwise>
  			</xsl:choose>
  		</xsl:if>
		</xsl:for-each>
	</xsl:template>


	<xsl:template name="audio-codec-start">
	  <xsl:param name="position" />
		<xsl:variable name="parsedAudioCodec" select="tokenize(//details/movie/audioCodec,' / ')"/>
		<xsl:for-each select="$parsedAudioCodec">
		  <xsl:if test="position() = $position">
  			<xsl:variable name="pass" select="position()" />
  			<xsl:choose>
  				<xsl:when test="contains($parsedAudioCodec[$pass],'AC3') or contains($parsedAudioCodec[$pass],'DTS') or contains($parsedAudioCodec[$pass],'MP3') or contains($parsedAudioCodec[$pass],'AAC') or contains($parsedAudioCodec[$pass],'TrueHD') or contains($parsedAudioCodec[$pass],'VORBIS') or contains($parsedAudioCodec[$pass],'orbis') or contains($parsedAudioCodec[$pass],'A_FLAC') or contains($parsedAudioCodec[$pass],'QDM') or contains($parsedAudioCodec[$pass],'microsoft')">
  					<xsl:if test="contains($parsedAudioCodec[$pass],'AC3')" ><img src="pictures/th_ac3.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'TrueHD')" ><img src="pictures/th_true_hd.png" align="top"/></xsl:if>
  					<xsl:choose>
  						<xsl:when test="contains($parsedAudioCodec[$pass],'DTS-HD')"><img src="pictures/th_dts_hd.png" align="top"/></xsl:when>
  						<xsl:otherwise><xsl:if test="contains($parsedAudioCodec[$pass],'DTS')"><img src="pictures/th_dts.png" align="top"/></xsl:if></xsl:otherwise>
  					</xsl:choose>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'MP3')"><img src="pictures/th_mp3.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'AAC')"><img src="pictures/thumb-AAC.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'VORBIS') or contains($parsedAudioCodec[$pass],'orbis')"><img src="pictures/thumb-Ogg.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'A_FLAC')"><img src="pictures/thumb-flac.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'QDM2') or contains($parsedAudioCodec[$pass],'QDMC')"><img src="pictures/thumb-Q.png" align="top"/></xsl:if>
  					<xsl:if test="contains($parsedAudioCodec[$pass],'microsoft')"><img src="pictures/thumb-MS.png" align="top"/></xsl:if>
  				</xsl:when>
  				<xsl:otherwise>&#160;</xsl:otherwise>
  			</xsl:choose>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>


	<xsl:template name="template-director">
	  <xsl:choose>
			<xsl:when test="director != 'UNKNOWN'">
				<xsl:value-of select="director" />
			</xsl:when>
			<xsl:otherwise>&#160;</xsl:otherwise>
    </xsl:choose>
	</xsl:template>

	<xsl:template name="template-actors">
		<xsl:if test="count(cast/actor)&gt;0">
			<xsl:for-each select="cast/actor[position()&lt;$actorNumAdj]">
			<div class="info">
				<xsl:value-of select="." />
			</div>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<xsl:template name="template-resolution">
	  <xsl:choose>
		  <xsl:when test="not(string(resolution))">&#160;</xsl:when>
		  <xsl:otherwise><xsl:value-of select="resolution" /></xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="template-subtitles">
		<xsl:choose>
	    <xsl:when test="contains(subtitles,'YES')">Yes</xsl:when>
	    <xsl:otherwise>No</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="template-videoOutput-text">
		<xsl:choose>
		  <xsl:when test="not(string(videoOutput))">&#160;</xsl:when>
		  <xsl:otherwise><xsl:value-of select="videoOutput" /></xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="template-libraryDescription">
		<xsl:choose>
      <xsl:when test="libraryDescription != 'UNKNOWN'"><xsl:value-of select="libraryDescription" /></xsl:when>
      <xsl:when test="not(string(libraryDescription))">&#160;</xsl:when>
			<xsl:otherwise>&#160;</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


</xsl:stylesheet>
