﻿<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:dd="http://www.HopAndVineHull.co.uk/DynamicData"
                exclude-result-prefixes="dd msxsl">

	<xsl:output method="xml" indent="yes" encoding="utf-8"
	            doctype-public="-//W3C/DTD XHTML 1.0 Strict//EN" 
	            doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

  <xsl:param name="CssHref" select="../Styles/Today.css"/>
  <xsl:param name="WholePage" select="false()"/>
  <xsl:param name="base" select="."/>
  
	<!-- c o l o u r s -->
	<xsl:variable name="colours">
		<colour type="beer"  number="0" name="LightSalmon" >#FFA07A</colour>
		<colour type="beer"  number="1" name="LightBlue"   >#ADD8E6</colour>
    <colour type="beer"  number="2" name="Gold"        >#FFD700</colour>
    <colour type="beer"  number="3" name="Khaki"       >#F0E68C</colour>

    <colour type="cider" number="0" name="GreenYellow" >#ADFF2F</colour>
    <colour type="cider" number="1" name="LightGreen"  >#90EE90</colour>
    <colour type="cider" number="2" name="Lime"        >#00FF00</colour>
  </xsl:variable>

	<xsl:template match="/">
    <xsl:choose>
      <xsl:when test="$WholePage">
        <html>
          <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <link rel="stylesheet" href="{$CssHref}" type="text/css"/>
            <title>The Hop And Vine - Online Blackboard</title>
            <base href="{$base}"/>
          </head>
          <body scroll="no">
            <xsl:apply-templates select="dd:HopAndVine"/>
          </body>
        </html>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="dd:HopAndVine"/>
      </xsl:otherwise>
    </xsl:choose>
	</xsl:template>
	
	<xsl:template match="dd:HopAndVine">
		<div class="blackboard">
			<div class="cellar">
				<xsl:apply-templates select="dd:Cellar"/>
			</div>
			<div class="kitchen">
				<xsl:apply-templates select="dd:Kitchen"/>
			</div>
		</div>
	</xsl:template>
	
	
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- I N   T H E   C E L L A R -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<xsl:template match="dd:Cellar">
    
    <!-- B E E R -->
    <table cellspacing="0" cellpadding="0">
      <tr>
        <th class="firstheadingCol1">
          <img src="../Images/Today/arrow.gif" alt=">" class="arrow" width="18" height="20"/>
          Cask Beer
        </th>
        <th class="firstheadingCol2">ABV</th>
        <th class="firstheadingCol3">Price</th>
      </tr>
      <xsl:apply-templates select="dd:Beer[@Status='On Tap']"/>
    </table>

    <!-- C I D E R -->
    <table cellspacing="0" cellpadding="0">
      <tr>
        <th class="firstheadingCol1">
          <img src="../Images/Today/arrow.gif" alt=">" class="arrow" width="18" height="20"/>
          Farmhouse Cider
        </th>
        <th class="firstheadingCol2">&#160;</th>
        <th class="firstheadingCol3">&#160;</th>
      </tr>
      <xsl:apply-templates select="dd:Cider[@Status='On Tap']"/>
    </table>

    <xsl:choose>
      <xsl:when test="count(dd:Beer[@Status = 'In The Cellar']) &lt; 6">
        <!-- Room for both -->
        <xsl:call-template name="OversizedLinedGlasses"/>
        <div class="headingDrop">
          <img src="../Images/Today/arrow.gif" alt=">" class="arrow" width="18" height="20"/>
          In the cellar
        </div>
      </xsl:when>
      <xsl:otherwise>
        <!-- Request only -->
<!--
        <xsl:call-template name="RequestYourFavourite">
          <xsl:with-param name="Style">float: right;</xsl:with-param>
        </xsl:call-template>
-->
        <div class="headingDrop">
          <img src="../Images/Today/arrow.gif" alt=">" class="arrow" width="18" height="20"/>
          In the cellar
        </div>
      </xsl:otherwise>
    </xsl:choose>
    
    <div class="InTheCellar">
			<xsl:apply-templates select="dd:Beer[@Status='In The Cellar' or @Status = 'On Next']"/>
      <xsl:text> </xsl:text>
		</div>
    
    <xsl:call-template name="DifferentBeersSold"/>		
<!--
    <xsl:if test="count(dd:Beer[@Status = 'In The Cellar']) &lt; 6">
      <xsl:call-template name="RequestYourFavourite">
          <xsl:with-param name="Style">margin-top: 1em;</xsl:with-param>
        </xsl:call-template>
    </xsl:if>
-->
    
	</xsl:template>
	
	<!-- B E E R -->
	<xsl:template match="dd:Beer[@Status='On Tap']">
		<xsl:variable name="pos" select="(position() - 1) mod 4"/>
		<xsl:call-template name="beer">
			<xsl:with-param name="color" select="msxsl:node-set($colours)/colour[@type='beer'][@number=$pos]"/>
		</xsl:call-template>
	</xsl:template>

	<!-- C I D E R -->	
	<xsl:template match="dd:Cider[@Status='On Tap']">
		<xsl:variable name="pos" select="(position() - 1) mod 3"/>
		<xsl:call-template name="beer">
			<xsl:with-param name="color" select="msxsl:node-set($colours)/colour[@type='cider'][@number=$pos]"/>
    </xsl:call-template>
	</xsl:template>
	
	<xsl:template name="beer">
		<xsl:param name="color" select="white"/>

    <xsl:variable name="padding-bottom">
      <xsl:choose>
        <xsl:when test="position() != last()">0.2em</xsl:when>
        <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="title">
    </xsl:variable>

    <tr style="color: {$color}; padding-bottom: {$padding-bottom};">
      <td class="BreweryBeer">
        <xsl:if test="dd:Brewery/@Location">
          <xsl:attribute name="title">
            <xsl:value-of select="dd:Brewery/@Location"/>
          </xsl:attribute>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="dd:Brewery/@URL != ''">
            <a href="{dd:Brewery/@URL}" style="color: {$color};">
              <xsl:value-of select="dd:Brewery"/>
            </a>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="dd:Brewery"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text> </xsl:text>
        <b><i><xsl:value-of select="dd:Beer"/></i></b>
      </td>
      <td class="right"><xsl:value-of select="dd:ABV"/>%</td>
      <td class="right">£<xsl:value-of select="dd:Price"/></td>
    </tr>

	</xsl:template>
	
	<!-- C O M I N G   S O O N -->
	<xsl:template match="dd:Beer[@Status='In The Cellar' or @Status='On Next']">
		<xsl:variable name="font-style">
			<xsl:choose>
				<xsl:when test="position() mod 2 = 0">italic</xsl:when>
				<xsl:when test="position() mod 2 = 1">normal</xsl:when>
			</xsl:choose>
		</xsl:variable>

    <xsl:variable name="color">
      <xsl:choose>
        <xsl:when test="@Status='On Next'">
          <xsl:text>white</xsl:text>        
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>gray</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    
		<div style="font-style: {$font-style}; color: {$color};">
			<span class="nowrap">
        <xsl:value-of select="dd:Brewery"/>
			</span>
      <xsl:text> </xsl:text>
      <span class="nowrap">
        <strong><xsl:value-of select="dd:Beer"/></strong>
        <xsl:if test="@Status='On Next'">
          <xsl:text> (on next)</xsl:text>
        </xsl:if>
        <span style="font-style: {$font-style}; color: gray;">
          <xsl:choose>
            <xsl:when  test="position() != last() - 1 and position() != last()">
              <xsl:text>, </xsl:text>
            </xsl:when>
            <xsl:when  test="position() = last() - 1">
              <xsl:text> and </xsl:text>
            </xsl:when>
            <xsl:when test="position() = last()">
              <xsl:text>.</xsl:text>
            </xsl:when>
          </xsl:choose>
        </span>
      </span>
		</div>

	</xsl:template>
	
	
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- I N   T H E   K I T C H E N -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<xsl:template match="dd:Kitchen">
      <xsl:apply-templates select="dd:Soups"/>
  		<xsl:apply-templates select="dd:Specials"/>
		  <xsl:apply-templates select="dd:Breads"/>
  </xsl:template>

  <!-- S O U P -->
  <xsl:template match="dd:Soups">
    <div class="firstheading">
      <img src="../Images/Today/arrow.gif" alt=">" class="arrow" width="18" height="20"/>
      Homemade Soup
    </div>
    <div class="food">
      <xsl:for-each select="dd:Soup">
        <xsl:if test="@Price">
          <span class="price">£<xsl:value-of select="@Price"/></span>
        </xsl:if>
        <ul>
          <li>
            <xsl:value-of select="@Title"/>
          </li>
        </ul>
      </xsl:for-each>
    </div>
  </xsl:template>

  <!-- S P E C I A L -->
  <xsl:template match="dd:Specials">
    <div class="heading">
      <img src="../Images/Today/arrow.gif" alt=">" class="arrow" width="18" height="20"/>
      Today's Specials
    </div>
    <div class="food">
      <xsl:for-each select="dd:Special">
        <xsl:if test="@Price">
          <span class="price">£<xsl:value-of select="@Price"/></span>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="@Title">
            <ul>
              <li><b><xsl:value-of select="@Title"/></b></li>
            </ul>
            <xsl:if test="text() != ''">
              <div class="FoodSpecial">
                <i><xsl:value-of select="text()"/></i>
              </div>
            </xsl:if>
          </xsl:when>
          <xsl:otherwise>
            <ul>
              <li class="FoodSpecial">
                <xsl:value-of select="text()"/>
              </li>
            </ul>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </div>
  </xsl:template>

  <!-- B R E A D S -->
  <xsl:template match="dd:Breads">
    <div class="heading">
      <img src="../Images/Today/arrow.gif" alt=">" class="arrow" width="18" height="20"/>
      Today's Breads
    </div>
    <div class="food">
      <xsl:for-each select="dd:Bread">
        <xsl:choose>
          <xsl:when test="@Availability='Available'">
            <xsl:choose>
              <xsl:when test="position() mod 2 = 0">
                <span class="BreadOn">
                  <img src="../Images/Today/bullet.gif" alt="o" width="16" Height="12"/>
                  <i><xsl:value-of select="."/></i>
                </span>
              </xsl:when>
              <xsl:otherwise>
                <span class="BreadOn">
                  <img src="../Images/Today/bullet.gif" alt="o" width="16" Height="12"/>
                  <b>
                    <xsl:value-of select="."/>
                  </b>
                </span>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <span class="BreadOff">
              <img src="../Images/Today/cross.gif" alt="x" width="16" Height="12"/>
              <xsl:value-of select="."/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text> </xsl:text>
      </xsl:for-each>
    </div>
  </xsl:template>
  
  <!-- N A M E D   T E M P L A T E S  -->
  <xsl:template name="DifferentBeersSold">
    
    <div class="beerssold">
      <xsl:text>Since opening we've sold </xsl:text>

      <xsl:choose>
        <xsl:when test="@DifferentBeersCount">
          <strong>
            <xsl:value-of select="@DifferentBeersCount"/>
          </strong>
          <xsl:text> different </xsl:text>
          <a href="../History/PastBeers.aspx?Type=Beer">real ales</a>
        </xsl:when>
        <xsl:otherwise>
          <strong>??</strong>
          <xsl:text> different real ales</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      
      <xsl:text> and </xsl:text>
      
      <xsl:choose>
        <xsl:when test="@DifferentCidersCount">
          <strong>
            <xsl:value-of select="@DifferentCidersCount"/>
          </strong>
          <a href="../History/PastBeers.aspx?Type=Cider"> ciders</a>
        </xsl:when>
        <xsl:otherwise>
          <strong>??</strong>
          <xsl:text> ciders</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      
      <xsl:text>.</xsl:text>
    </div>
    
  </xsl:template>

  <xsl:template name="OversizedLinedGlasses">

    <xsl:param name="class" select="'OversizedLinedGlasses'"/>

    <div class="{$class}">
      <xsl:text>All real ales and ciders are sold in oversized lined glasses. </xsl:text>
      <xsl:text>Guaranteeing a </xsl:text>
      <a href="http://www.takeittothetop.co.uk/">full pint</a>
      <xsl:text>.</xsl:text>
    </div>
    
  </xsl:template>


  <xsl:template name="RequestYourFavourite">

    <xsl:param name="Style" select="'align: left;'"/>

    <div class="RequestYourFavourite" style="{$Style}">
      <b>Fancy a pint of your favourite?</b>
      <br/>
      <a href="../Requests/Requests.aspx">Ask us</a>
      <xsl:text> and we will endeavour to get it in for you.</xsl:text>
    </div>

  </xsl:template>


</xsl:stylesheet>