<?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"

	exclude-result-prefixes="unused"
> 
	<xsl:output 
		encoding	= "utf-8" 
		method		= "html" 
		indent		= "yes" 
		unused:doctype-public	= "-//W3C//DTD HTML 4.01 Transitional//EN" 
		unused:doctype-public-2  = "-//W3C//DTD XHTML 1.0 Transitional//EN"
		doctype-public  = "-//W3C//DTD XHTML 1.0 Strict//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}/css/layout.css" type="text/css" media="screen" charset="utf-8" />
			<link rel="stylesheet" href="{$base}/css/jd.gallery.css" type="text/css" media="screen" charset="utf-8" />

			<!-- link rel="stylesheet" href="{$base}/default.css" alternate="no" / -->
			<!-- script src="{$base}/default.js" type="text/javascript"></script -->
			<title><xsl:value-of select="$title" /></title>

		</head>
		<body>
			<script src="{$base}/scripts/mootools.v1.11.js"         type="text/javascript"></script>
			<!-- script src="{$base}/scripts/HistoryManager.js"         type="text/javascript"></script -->
			<script src="{$base}/scripts/jd.gallery.v2.js"          type="text/javascript"></script>
			<script src="{$base}/scripts/jd.gallery.set.js"         type="text/javascript"></script>
			<script src="{$base}/scripts/jd.gallery.transitions.js" type="text/javascript"></script>
			<script language="javascript" type="text/javascript"><![CDATA[
				var myGallery;
				function startGallery() {
					myGallery = new gallery($('myGallery'), {
						timed: true,
						delay: 7000
					});
				}
				
				window.addEvent('domready',startGallery);
		
				function toggle() {
		  			if (myGallery.options.timed) { 
						myGallery.clearTimer(); 
						myGallery.options.timed=false; 
					} else { 
						myGallery.options.timed=true; 
						myGallery.prepareTimer();
					}
				} 
			]]></script>

		   <h1><span class="company"><xsl:value-of select="$title" /></span></h1>
			<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 style="text-align: right;">
		  <a href="#" onclick="toggle(); return false;">slide</a> -
		  <a href="{$base}/prefs/">Preferences</a> - <a href="http://www.xmlautoindex.org/">xmlAutoIndex</a>
		</div>

		<div style="padding: 5px;">
		  <a href="..">..</a>
		  <xsl:text> </xsl:text>
		  <xsl:apply-templates select="file[mime-type/@name='httpd/unix-directory']" mode="folder"/>
		</div>
		
		<br/><br/>

		<div class="content">
		  <div id="myGallery">
			<xsl:apply-templates select="file[@slideshow='true']" mode="image"/>
	          </div>
		</div>

	</xsl:template>


	<xsl:template match="file" mode="folder">
		<a href="{@link}">
			<xsl:value-of select="@name" />
		  <!--xsl:call-template name="display-name">
		    <xsl:with-param name="name"><xsl:value-of select="@name" /></xsl:with-param>
		  </xsl:call-template-->
		</a> 
		<xsl:text> </xsl:text>
	</xsl:template>
	
	<xsl:template match="file" mode="image">
		<div class="imageElement">
			<h3>
			<xsl:value-of select="@name" />
			</h3>
			<p>//TODO//</p>
			<a href="{@link}" title="open image" class="open"></a>
			<img src="{previews/preview[@format='size2']/@href}" class="full" />
			<img src="{previews/preview[@format='thumb']/@href}" class="thumbnail" />
		</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>


