<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:strip-space elements="*"/>
	<xsl:output method="html" indent="yes" encoding="utf-8"/>

	<xsl:template match="PAGES-TREE">
		<xsl:param name="isSwitchable"/>
		<xsl:param name="onSelect"/>
		<xsl:param name="onAfterSelect"/>
		<xsl:param name="onChange"/>
		<xsl:param name="onCheck"/>		
		<script type="text/javascript" language="javascript" src="/js/pages_tree.js?{$version}.{$build}"/>
		<div id="{@NAME}">
			<xsl:attribute name="style">width:100%; height:100%; white-space: nowrap; table-layout: fixed;<xsl:choose>
				<xsl:when test="$isSwitchable='true'">overflow-y: auto;</xsl:when>
				<xsl:otherwise>overflow: auto;</xsl:otherwise>
			</xsl:choose></xsl:attribute>
			<script type="text/javascript" language="javascript">
				<xsl:comment>
					SbInitTree('<xsl:value-of select="@NAME"/>', '<xsl:value-of select="@STATIC"/>', '<xsl:value-of select="@WITH-LINES"/>', '<xsl:value-of select="@DRAGGABLE"/>', '<xsl:value-of select="@CHECKABLE"/>', '<xsl:value-of select="@SELECTABLE"/>', <xsl:call-template name="PAGES-TREE-INIT-PARAM-FUNCTION"><xsl:with-param name="method" select="$onSelect"/></xsl:call-template>, <xsl:call-template name="PAGES-TREE-INIT-PARAM-FUNCTION"><xsl:with-param name="method" select="$onChange"/></xsl:call-template>, <xsl:call-template name="PAGES-TREE-INIT-PARAM-FUNCTION"><xsl:with-param name="method" select="$onCheck"/></xsl:call-template>, <xsl:call-template name="PAGES-TREE-INIT-PARAM-FUNCTION"><xsl:with-param name="method" select="$onAfterSelect"/></xsl:call-template>);
					var tree = document.getElementById('<xsl:value-of select="@NAME"/>');
					<xsl:apply-templates select="@MAX-ROOT-PAGES|@MAX-PAGES|@MAX-LEVEL"/>
				//</xsl:comment>
			</script>
			<xsl:apply-templates select="PAGES-TREE-PAGE">
				<xsl:with-param name="treeId" select="@NAME"/>
			</xsl:apply-templates>
		</div>
		<script type="text/javascript" language="javascript">
			<xsl:comment>
				SbRefreshTree('<xsl:value-of select="@NAME"/>');
			//</xsl:comment>
		</script>
	</xsl:template>

	<xsl:template match="PAGES-TREE/@MAX-ROOT-PAGES">
		tree.setMaxRootPages(<xsl:value-of select="."/>);
	</xsl:template>

	<xsl:template match="PAGES-TREE/@MAX-PAGES">
		tree.setMaxPages(<xsl:value-of select="."/>);
	</xsl:template>

	<xsl:template match="PAGES-TREE/@MAX-LEVEL">
		tree.setMaxLevel(<xsl:value-of select="."/>);
	</xsl:template>

	<xsl:template name="PAGES-TREE-INIT-PARAM-FUNCTION">
		<xsl:param name="method"/>
		<xsl:choose>
				<xsl:when test="$method"><xsl:value-of select="$method"/></xsl:when>
				<xsl:otherwise>null</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="PAGES-TREE-PAGE">
		<xsl:param name="treeId"/>

		<div id="{@ID}" valign="middle">
			<img id="{@ID}State" border="0" width="19px" align="middle" src="/images/blank.gif"/>
			<img id="{@ID}Line" border="0" width="19px" align="middle" src="/images/blank.gif"/>
			<input id="{@ID}Check" type="checkbox" style="display: inline; vertical-align: middle;"/>
			<img id="{@ID}Icon" border="0" width="16" height="16" style="display: inline; vertical-align: middle;">
				<xsl:choose>
					<xsl:when test="@TYPE!='Simple'">
						<xsl:choose>
							<xsl:when test="@SHOW-IN-NAVIGATION='visible'">
								<xsl:attribute name="src">/modules/<xsl:value-of select="@TYPE"/>/images/icon.gif</xsl:attribute>
							</xsl:when>
							<xsl:otherwise>
								<xsl:attribute name="src">/modules/<xsl:value-of select="@TYPE"/>/images/hidden_icon.gif</xsl:attribute>
							</xsl:otherwise>
						</xsl:choose>	
					</xsl:when>
					<xsl:otherwise>
						<xsl:choose>
							<xsl:when test="@SHOW-IN-NAVIGATION='visible'">
								<xsl:attribute name="src"><xsl:value-of select="$skinPath"/>/icons/HTMLPageIcon.gif</xsl:attribute>
							</xsl:when>	
							<xsl:otherwise>
								<xsl:attribute name="src"><xsl:value-of select="$skinPath"/>/icons/HTMLPageHiddenIcon.gif</xsl:attribute>
							</xsl:otherwise>
						</xsl:choose>	
					</xsl:otherwise>
				</xsl:choose>
			</img>
			<span id="{@ID}Span">
				<xsl:choose>
					<xsl:when test="@SHOW-IN-NAVIGATION='visible'">
						<xsl:attribute name="style">vertical-align: middle;</xsl:attribute>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="style">vertical-align: middle; color: gray;</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:value-of select="@TITLE"/>
			</span>
			<xsl:apply-templates select="PAGES-TREE-PAGE">
				<xsl:with-param name="treeId" select="$treeId"/>
			</xsl:apply-templates>
		</div>
		<script type="text/javascript" language="javascript">
			<xsl:comment>
				SbInitNode('<xsl:value-of select="$treeId"/>', '<xsl:value-of select="@ID"/>', '<xsl:value-of select="@F-NAME"/>', '<xsl:value-of select="@TYPE"/>', '<xsl:value-of select="@SELECTED"/>', '<xsl:value-of select="@ENABLED"/>', '<xsl:value-of select="@SHOW-IN-NAVIGATION"/>');
			//</xsl:comment>
		</script>
	</xsl:template>

</xsl:stylesheet>
