<?xml version="1.0" encoding="iso-8859-1"?>

<!--
        #
        #  Copyright (C) 2005 Vanbelle Edouard
        #
        #  This program is free software; you can redistribute it and/or
        #  modify it under the terms of the GNU General Public License
        #  as published by the Free Software Foundation; either version 2
        #  of the License, or (at your option) any later version.
        #
        #  This program is distributed in the hope that it will be useful,
        #  but WITHOUT ANY WARRANTY; without even the implied warranty of
        #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        #  GNU General Public License for more details.
        #
        #  You should have received a copy of the GNU General Public License
        #  along with this program; if not, write to the Free Software
        #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
        #
  -->

<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:unused="http://www.vanbelle.fr/xml/unused"
	unused:xmlns="http://www.w3.org/1999/xhtml"
> 
	<xsl:output 
		encoding	= "utf-8" 
		method		= "html" 
		indent		= "yes" 
		doctype-public	= "-//W3C//DTD HTML 4.01 Transitional//EN" 
		unused:doctype-public  = "-//W3C//DTD XHTML 4.01//EN"
		standalone	= "yes"
	/>

	<!-- loading translation system -->
	<xsl:variable name="lang" select="document('lang/default.xml.fr')/messages/message" />

	<xsl:strip-space elements="*" />

	<xsl:variable name="base">/.libs/themes/<xsl:value-of select='//autoIndex/display/@theme'/></xsl:variable>

	<xsl:variable name="selected-file" select="//autoIndex/files/file[ @selected='true' ]" />
	<xsl:variable name="format"        select="//autoIndex/display/@format" />
	<xsl:variable name="title">
		<xsl:choose>
		<xsl:when test="count( $selected-file)">
			<xsl:apply-templates select="$selected-file" mode="title"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="//autoIndex/title"/>
		</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:template match="file" mode="title">
		<xsl:param name="nb-before" select="count( preceding-sibling::*[@slideshow = 'true'])"/>
		<xsl:param name="nb-after"  select="count( following-sibling::*[@slideshow = 'true'])"/>
		<xsl:value-of select="$nb-before + 1" /> / <xsl:value-of select="$nb-before + 1 + $nb-after" /> : <xsl:value-of select="@name"/>
	</xsl:template>
	
	<!-- ###################################################################################################################### -->
	<xsl:template match="/autoIndex">
	<html>
		<head>
			<xsl:if test="display/@timeout != ''">
				<xsl:apply-templates select="$selected-file" mode="refresh-next">
					<xsl:with-param name="timeout" select="display/@timeout"/>
				</xsl:apply-templates>
			</xsl:if>

			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<link rel="icon" href="/favicon.ico" />
			<link rel="stylesheet" href="{$base}/default.css" alternate="no" />
			
			<xsl:comment>compliance patch for microsoft browsers</xsl:comment>
			<xsl:comment><![CDATA[[if lt IE 7]><script src="/.libs/ie7/ie7-standard-p.js" type="text/javascript"></script><![endif]]]></xsl:comment>
			
			<script src="{$base}/default.js" type="text/javascript"></script>
			<title><xsl:value-of select="$title" /></title>
		</head>
		<body>
			<xsl:apply-templates select="files" mode="folder" />
		</body>
		
	</html>
        </xsl:template>

	
	<xsl:template match="file" mode="refresh-next">
		<xsl:param name="timeout"/>
		<xsl:param name="next" select="following-sibling::*[@slideshow = 'true'][1]" />
		<xsl:if test="$next/@link !=''">
			<meta http-equiv="Refresh" >
				<xsl:attribute name="content"><xsl:value-of select="$timeout"/>;URL=<xsl:value-of select="$next/@link"/>?display=slide&amp;timeout=<xsl:value-of select="$timeout"/></xsl:attribute>
			</meta>
		</xsl:if>
	</xsl:template>



	<!-- ###################################################################################################################### -->
	<xsl:template match="files" mode="folder">
	        <div>
		  <a href="{$base}/prefs/">Preferences</a> - <a href="http://www.xmlautoindex.org/">xmlAutoIndex</a>
		</div>

		<div class="file" title="..">
		  <div class="filecontent">
		    <a href="..">
		      <img alt="httpd/unix-directory" src="{$base}/icons/httpd-unix-directory.png" />
		      <br/>
		      ..
		    </a>
		    <div class="fileoption">
		      <br/>
		    </div>
		  </div>
		</div>
		<xsl:apply-templates select="file" mode="folder"/>
	</xsl:template>


	<xsl:template match="file" mode="folder">
		<div 
		        class      = "file" 
			title      = "{@name}"
		>
		  <div class="filecontent">
			<a href="{@link}">
			  <img  alt="{mime-type/@name}">
				<xsl:attribute name="src"><xsl:value-of select="previews/preview[@format='thumb']/@href"/></xsl:attribute>
			  </img>
			<br/>
			<xsl:call-template name="display-name">
				<xsl:with-param name="name"><xsl:value-of select="@name" /></xsl:with-param>
			</xsl:call-template>
			</a>
			<div class="fileoption">
					<br/>
			</div>
		  </div>
		</div>
	</xsl:template>



	<!-- ###################################################################################################################### -->
	<xsl:template name="display-name">
		<xsl:param name="name"/>
		<xsl:choose>
			<xsl:when test="string-length( $name) &gt; 20">
				<xsl:value-of select="substring( $name, 1, 16)" />...
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$name" /> 
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="display-directoryname">
		<xsl:param name="name"/>
		<xsl:choose>
			<xsl:when test="string-length( $name) &gt; 18">
				...<xsl:value-of select="substring( $name, string-length( $name) - 16, 17)" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$name" /> 
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>


