<%
import se.datadosen.util.*;  
//required variables for numerous parts of page  

File resDir = (File)album.get("resDir");
File root = (File)album.get("root");
String rootName = album.get("rootName");

//Multilevel index link function
void writePath(File dir, String prefix) 
{ 
  boolean topLevel = fileVariables.get(dir) == null; 

  if (!topLevel) 
  {
    writePath(dir.getParentFile(), prefix + "../"); 
    out.print(" > ");
  }

  if (prefix.length() > 0) 
    out.print("<a href=\"" + prefix + engine.getIndexPageName() + engine.getPageExtension() + "\">"); 
  else
    out.print("<a href=\"" + indexPage + "\">"); 

  out.print((topLevel ? "<b>" + album.get("rootName") + "</b>" : dir.getName()) + "</a>");
} 

/*-- Reset file dates to EXIF dates 
    Remove or comment out if not desired
*/
//This code converts the file dates to the original EXIF date.
//Add your own date pattern if it doesn't have the one you want.
if (originalDate != void)
{
  import java.text.*;
    Date parseExifDate(String exifDate) {
        String[] patterns = {
         "MMM dd, yyyy HH:mm", //new pattern
         "MM/dd/yyyy HH:mm",
         "yyyy:MM:dd HH:mm:ss",
         "yyyy:MM:dd HH:mm",
         "yyyy-MM-dd HH:mm:ss",
         "yyyy-MM-dd HH:mm",
         "yyyyMMdd HHmmss",
         "yyyyMMdd HHmm"
        };
        // Try these patterns. Add new to make this method even smarter
        for (int i=0; i<patterns.length; i++) {
            try {
                DateFormat parser = new SimpleDateFormat(patterns[i]);
                return parser.parse(exifDate);
            }
            catch (ParseException ex) {}
        }
        return null;  // We cannot parse
    }

  Date d = parseExifDate(originalDate);
  if (d != null) {
    files[imageNum-1].setLastModified(d.getTime());
  }
}

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>$label | $title |Image $imageNum of $totalImages</TITLE>
<LINK HREF="$stylePath" REL=stylesheet>
</HEAD>
<BODY ID="slide">
<table width="100%">
<tr class="headerRow">
  <td>
    <div class="indexLinks" align="left"><%= writePath(imageDirectory, "../") %> </div>
    <div>&nbsp;</div>
  </td>
</tr>
<tr class="titleRow">
  <td align="center">
    <div class="name" align="left">$label</div>
  </td>
</tr>   
<tr>
  <td>
    <table cellpadding="5" align="center" border="0">
      <tr>
        <td align="center" width="33%">
        <ja:if exists="previousPage">
          <a href="$previousPage"><img align="texttop" src="$resPath/previous.gif" border="0" alt="Previous Image">
          <br><span class="smallText">Previous Image</span></a>
        </ja:if>
        <ja:else>
          <img src="$resPath/previous_disabled.gif" align="texttop" border="0" alt="No Previous Image">
          <br><span class="smallText">No Previous Image</span>
        </ja:else>
        </td>
        <td align="center" width="34%"> 
          <a href="../$indexPage"><img align="texttop" src="$resPath/index.gif" border="0" alt="Return to Thumbnails Index Page">
          <br><span class="smallText">Return to Thumbnails</span></a>
        </td>
        <td align="center" width="33%">
        <ja:if exists="nextPage">
          <a href="$nextPage"><img align="texttop" src="$resPath/next.gif" border="0" alt="Next Image">
          <br><span class="smallText">Next Image</span></a>
        </ja:if>
        <ja:else>
          <img src="$resPath/next_disabled.gif" align="texttop" border="0" alt="No Next Image">
          <br><span class="smallText">No Next Image</span>
        </ja:else>  
        </td> 
      </tr> 
    </table>  

    <!-- Image, maybe with link to original -->
    <TABLE align="center">
      <tr>
        <TD align="center">
        <ja:if exists=originalPath>
          <A HREF="$originalPath">
          <IMG CLASS="image" IMG SRC="$imagePath" BORDER=0 ALT="Click for original image <%=fileSize/1024%>k <%=originalWidth%>x<%=originalHeight%>">
          </A>
        </ja:if>
        <ja:else>
           <IMG class="mainImage" SRC="$imagePath" width="<%=imageWidth%>" height="<%=imageHeight%>">
        </ja:else>
        </TD>
      </tr>
    </TABLE>

    <TABLE WIDTH="100%">
      <tr>
        <!-- Previous thumbnail -->
        <TD rowspan="2" WIDTH="33%" ALIGN="left" height="100%">
          <ja:if exists="previousPage">
          <% //have thumb label a maximum length so that its not longer than image
           int maxLength=20;
           String initPrevLabel = previous.get("label");
           String finalPrevLabel;
           if (initPrevLabel.length() > maxLength)  //thumbCommentLength defined at beginning of file
           {
              finalPrevLabel = initPrevLabel.substring(0,maxLength-4);
              finalPrevLabel = finalPrevLabel + "...";
           }
           else
              finalPrevLabel = initPrevLabel;
          %>  
          <table>
            <tr>  
              <td class="tdNav">
                <A HREF="$previousPage">
                <div align="center">Previous Image</div>
                <div><IMG CLASS="navImg" align="texttop" SRC="<%=previous.get("thumbPath")%>" ALT="Previous image" BORDER=0></div>
                <DIV align="center"><%= finalPrevLabel %></div>
                </A>
              </td>
            </tr>
          </table>
          </ja:if>  
          <ja:else>
          <table height="100%">
            <tr>  
              <td class="tdNav">
                <div align="center">No Previous Image</div>                                   
              </td>
            </tr>
          </table>  
          </ja:else>
        </td> 

        <!-- Current image comments -->
        <TD WIDTH="34%" valign="top" ALIGN="center">      
          <% 
          if (comment != void)
          {
            out.print(comment);
          }
          
          //extract comment from a "_<filename>.inc" comment text file if it exists
          String filename = fileName;
           if (fileName != void && fileName.length() >= 4)   
           {
             filename =  fileName.substring(0, fileName.length()-4);
           }
          File captionFile = new File(imageDirectory, "_" + filename + ".inc");
          if (captionFile.exists())
          {
            String commentString = IO.readTextFile(captionFile);
            if (commentString != null) 
            {
              out.print(commentString);
            }
          }         
          %>
        </TD>

        <!-- Next thumbnail -->
        <TD rowspan="2" WIDTH="33%" ALIGN="right" height="100%">
          <ja:if exists="nextPage">
          <% //have thumb label a maximum length so that its not longer than image
           int maxLength=20;
           String initNextLabel = next.get("label");
           String finalNextLabel;
           if (initNextLabel.length() > maxLength)  //thumbCommentLength defined at beginning of file
           {
              finalNextLabel = initNextLabel.substring(0,maxLength-4);
              finalNextLabel = finalNextLabel + "...";
           }
           else
              finalNextLabel = initNextLabel;
          %>
          <table>
            <tr>
              <td class="tdNav" align="right">
                <A HREF="$nextPage">
                <div align="center">Next Image</div>
                <div><IMG class="navImg" align="texttop" SRC="<%=next.get("thumbPath")%>" ALT="Next image" BORDER=0></div>
                <div align="center"><%= finalNextLabel %></div>
                </A>
              </td>
            </tr>
          </table>
        </ja:if>
        <ja:else>
          <table height="100%">
            <tr>  
              <td class="tdNav" valign="middle">
               No Next Image                                  
              </td>
            </tr>
          </table>  
        </ja:else>
        </TD>
      </tr>
      <tr>
        <td width="34%" valign="bottom" align="center">
        <div align="center">
          <a href="../$indexPage"><img src="$resPath/index.gif" align="texttop" border="0" alt="Return to Thumbnails">
          <br><span class="smallText">Return to Thumbnails</span></a>
        </div>
        </td>
      </tr>
    </TABLE>
  </td>
</tr>
</table>
<P>
  <SMALL>Generated by <A HREF="$generatorUrl" TARGET="_blank"> $generator</A>
  </SMALL>
</P>
</BODY>
</HTML>