<?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"
	xmlns:svg="http://www.w3.org/2000/svg"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xlink="http://www.w3.org/1999/xlink"
> 
	<xsl:output 
		encoding	= "utf-8" 
		method		= "xml" 
		indent		= "yes" 
		standalone	= "yes"
		unused:doctype-public  = "-//W3C//DTD HTML 4.01 Transitional//EN"
		doctype-public  = "-//W3C//DTD XHTML 1.0 Transitional//EN"
	/>

	<!-- 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:template match="/autoIndex">
	<html>
		<head>
			<link rel="stylesheet" href="{$base}/default.css" alternate="no" />
			
			<script src="{$base}/default.js" type="text/javascript"></script>
			
			<title><xsl:value-of select="//autoIndex/title" /></title>
		</head>
		<body onload="checkNavigator();">
			<div style="position: fixed; top: 0px; left: 0px; width: 179px; height: 100%; background: #dddddd;">
			  <a  style="display:block;" href="{$base}/prefs/">Preferences</a>
			  <a  style="display:block;" href="http://www.xmlautoindex.org/">xmlAutoIndex</a>
			  <br/><br/>
			<b title="{//autoIndex/title}">
			<xsl:call-template name="display-directoryname">
				<xsl:with-param name="name" select="//autoIndex/title" />
			</xsl:call-template>
			</b>
			<br/>
			  <div class="actions">

			  <xsl:apply-templates select="parents/parent" />
			  </div>
			</div>
			<!--svg:svg width="20%" height="100%" viewBox="0 0 800 600" style="position: fixed; top: 0px; left: 0px;" preserveAspectRatio="none">
				<svg:rect x="0" y="0" width="100%" height="100%" fill="#dddddd;" fill-opacity="1"  />
				<svg:rect x="6" y="6" width="788" height="588" fill="#ffffff;" fill-opacity="1" rx="18" ry="18" />
				<svg:image x="550" y="400" width="260" height="260" xlink:href="{$base}/background/platine.jpg" />
			</svg:svg-->
			<!--div style="position: absolute; top: 0px; left: 0px; margin: 12px; width: 700px; height: 400px; border: 1px solid gray; overflow: auto;" -->
			<div style="position: absolute; top: 0px; left: 180px; margin: 6px; height: 100%;" >
  			  <xsl:apply-templates select="files" mode="folder" />
			</div>

			<svg:svg id="image" width="100%" height="100%" viewBox="0 0 800 600" style="position: fixed; top: 0px; left: 0px; display: none;" preserveAspectRatio="XmidYmid">
				<!--svg:rect x="0" y="0" width="100%" height="100%" fill="#000000;" fill-opacity="0.3" /-->
				<svg:rect x="40" y="30" width="720" height="540" fill="#eeeeee;" fill-opacity="1" stroke="blue" stroke-width="0.2" rx="18" ry="18" />
			        <!-- svg:text y="48" x="400" fill="black" text-anchor="middle">Keke</svg:text -->
				<svg:image x="380" y="280" width="16" height="16" xlink:href="{$base}/background/loading-gray.gif" />
				<svg:image id="display" x="50" y="50" width="700" height="500" xlink:href="" stroke="black" stroke-width="3px"/>
				<svg:rect x="40" y="20" width="720" height="540" fill="#ffffff;" fill-opacity="0" rx="18" ry="18" 
					cursor="pointer"
			        	onclick="document.getElementById('image').style.display='none'; document.getElementById('display').setAttribute('xlink:href','');"
				/>
			</svg:svg>
		</body>
		
	</html>
        </xsl:template>

	<xsl:template match="parent">

	
		<xsl:choose>
			<xsl:when test="@selected='true'">
				<a href="../{@link}"><img src="{$base}/nav/crystal/ok.png"/>&#160;<xsl:value-of select="@name"/></a>
				<xsl:for-each select='//autoIndex/files/file[mime-type/@name="httpd/unix-directory"]' >
				  <a href="{@link}">&#160;&#160;<img src="{$base}/nav/crystal/fileopen.png"/>&#160;<xsl:value-of select="@name"/></a> 
				</xsl:for-each>
			</xsl:when>
			<xsl:when test="@link = '.'">
				<a href="../{@link}"><img src="{$base}/nav/crystal/previous.png"/>&#160;<i>parent</i></a>
			</xsl:when>
			<xsl:otherwise>
				<a href="../{@link}"><img src="{$base}/nav/crystal/fileopen.png"/>&#160;<xsl:value-of select="@name"/></a>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- ###################################################################################################################### -->
	<xsl:template match="files" mode="folder">
		<!--div class      = "file"  >
		  <svg:svg width="120px" height="120px" viewBox="-60 -60 120 120">

		      <svg:g transform="scale(0.9)"
				onmouseover="this.setAttribute('transform','scale(1.0)');"
				onmouseout="this.setAttribute('transform','scale(0.9)');"
			>
			<svg:a xlink:href="..">
			  <svg:image x="-35" y="-35" width="70" height="70" xlink:href="{$base}/icons/httpd-unix-directory.png" />
			<svg:text x="0" y="44" fill="black" text-anchor="middle">..</svg:text>
			    <svg:rect class="button" x="-60" y="-60" rx="16" ry="16" width="120" height="120"
			    title="parent directory"
			    /> 
			</svg:a>
			</svg:g>
		  </svg:svg>
		</div-->
			<xsl:apply-templates select="file" mode="folder"/>
	</xsl:template>


	<xsl:template match="file" mode="folder">

		<div class      = "file" >
		<xsl:choose>
		<xsl:when test="starts-with( mime-type/@name, 'image')">
		  <svg:svg width="120px" height="120px" viewBox="-60 -60 120 120">
		      <svg:g transform="scale(0.9)"
				onmouseover="this.setAttribute('transform','scale(1.0)');"
				onmouseout="this.setAttribute('transform','scale(0.9)');"
			>
			<!--svg:rect x="-42" y="-50" width="84" height="84" stroke="red" fill="none" /-->
			  <svg:image x="-42" y="-50" width="84" height="84" preserveAspectRatio="xMidYMax">
				<xsl:attribute name="xlink:href"><xsl:value-of select="previews/preview[@format='thumb']/@href"/></xsl:attribute>
			</svg:image>
			<svg:text x="0" y="50" fill="black" text-anchor="middle">
			<xsl:call-template name="display-name">
				<xsl:with-param name="name"><xsl:value-of select="@name" /></xsl:with-param>
			</xsl:call-template>

			</svg:text>
			    <svg:rect class="button" x="-60" y="-60" rx="16" ry="16" width="120" height="120"
			    	title="display image"
			    	cursor="pointer"
			    	onclick="show('{previews/preview[@format='size2']/@href}');"
				/>
		     </svg:g>
		  </svg:svg>
		    </xsl:when>
		    <xsl:otherwise>
			  <svg:svg width="120px" height="120px" viewBox="-60 -60 120 120">

		      <svg:g transform="scale(0.9)"
				onmouseover="this.setAttribute('transform','scale(1.0)');"
				onmouseout="this.setAttribute('transform','scale(0.9)');"
			>
			  <svg:image x="-35" y="-35" width="70" height="70">
				<xsl:attribute name="xlink:href"><xsl:value-of select="previews/preview[@format='thumb']/@href"/></xsl:attribute>
			</svg:image>
			<svg:text x="0" y="44" fill="black" text-anchor="middle">
			<xsl:call-template name="display-name">
				<xsl:with-param name="name"><xsl:value-of select="@name" /></xsl:with-param>
			</xsl:call-template>

			</svg:text>
			<svg:a xlink:href="{@link}">
			    <svg:rect class="button" x="-60" y="-60" rx="16" ry="16" width="120" height="120"
			    title="open file"
			    /> 
			    </svg:a>
			</svg:g>
		  </svg:svg>
		    
		    </xsl:otherwise>
		    </xsl:choose>
  	    </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>


