<%
  import se.datadosen.util.*;

  String sOutput    		= "";
  String jsPlugins   		= "";
  String jsFoldState 		= "";
  String sInformationPanel	= "";
  String sActivitiesPanel	= "";
  SmartResourceBundle texts	= null;

  // Add functionality common to the plug-in mechanism
  engine.processBeanShellFile(new File(skinDirectory, "plugins.bsh"));
  
  // If meta.properties exists in the image directory and contains
  // an alternative title, use it instead of the directory name
  File propsFile = new File(imageDirectory, "meta.properties");
  if (propsFile.exists()) {
    Properties props = IO.readPropertyFile(propsFile);
    String newTitle = props.get("title");
    if (newTitle != null) title = newTitle;
  }
  
  String spacerImage(height) {
  	String sOut = "";
  	int lHeight = 0;
  	
  	lHeight = (int)((94 - height) / 2);
  	if (lHeight > 0) {
  		sOut += "<img style=\"visibility:hidden;\" src=\"" + resPath + "/1x1.gif\" width=\"94\" height=\"" + lHeight + "\" border=\"0\">";
  	}
  	
  	return sOut;
  }
  
  String imageCount() {
  	String sOut = "";
  	int lLength = files.length;
  	
  	if (lLength > 0) {
  		if (indexNum == void) {
  			sOut += "($text.image 1 $text.through " + indexImageCount + " $text.of " + lLength + ")";
  		} else {
  			sOut += "($text.image " + ((indexNum - 1) * (cols * rows) + 1) + " $text.through " + ((indexNum - 1) * (cols * rows) + indexImageCount) + " $text.of " + lLength + ")";
  		}
  	}
  	
  	return sOut;
  }
%><ja:if test="$useFolderView"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"></ja:if><ja:else><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"></ja:else>
<html>
<head>
<!-- saved from url=(0013)about:internet -->
	<meta http-equiv="content-type" content="text/html; charset=$textEncoding" />
	<meta name="description" content="Album generated with $generator and the XP skin v2.2. More skins available at http://jrepository.engblom.org.">
	<title><%=title%></title>
	<ja:if exists="parentIndexPage"><link rel="up" href="$parentIndexPage"></ja:if>
<%
// If we are using plug-ins - include their CSS-files and evaluate any head.htt files found
if (Plugins != null && Plugins != void) {
	sOutput = "";
	String[] arrPlugins = Plugins.split("#");
	for (int i = 0; i < arrPlugins.length; i++) {
		// Read localized strings for plug-in
		texts = getResources(arrPlugins[i]);

		File fCSS = new File(resDirectory, arrPlugins[i] + "/styles.css");
		if (fCSS.exists())
			sOutput += "	<link href=\"" + resPath + "/" + arrPlugins[i] + "/styles.css\" rel=\"stylesheet\">";
		File fHead = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/head.htt");
		if (fHead.exists())
			sOutput += engine.processTemplate(IO.readTextFile(fHead));
		fHead = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/headIndex.htt");
		if (fHead.exists())
			sOutput += engine.processTemplate(IO.readTextFile(fHead));
	}
}
%><%=sOutput%>
	<link href="$stylePath" rel="stylesheet">
<script language="javascript" src="$resPath/x.js"></script>
<script language="javascript">
function readCookie(name) {
	var nameEQ = name + "="
	var ca = document.cookie.split(';')
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length)
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
	}
	return '';
}
function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires="+date.toGMTString()
	}
	else expires = ""
	document.cookie = name+"="+value+expires+"; path=/"
}
function setSlideShowCookie() {
	saveCookie('slideShow', 'true');
}
<ja:if test="$useFolderView">
function toggleNode(index) {
	var sItem    = '|' + index + '|';
	var sFolders = readCookie('Folders');
	var lStart   = sFolders.indexOf(sItem);
	if (lStart == -1) {
		sFolders += sItem;
		document.images['img' + index].src = '$resPath/TreeMinus.gif';
		document.getElementById('folder' + index + 'c').style.display = 'block';
	} else {
	    sFolders = sFolders.substring(0, lStart) + sFolders.substring(lStart + sItem.length, sFolders.length);
		document.images['img' + index].src = '$resPath/TreePlus.gif';
		document.getElementById('folder' + index + 'c').style.display = 'none';
	}
	saveCookie('Folders', sFolders);
}
</ja:if>
function toggleVisibility(div) {
	try {
		var elem = xGetElementById(div);
		if (!elem) 
			return;
			
		if (elem.style.overflow == '' || elem.style.overflow == 'visible') {
			saveCookie(div + 'Overflow', 'hidden', 1000);
		} else {
			saveCookie(div + 'Overflow', 'visible', 1000);
		}
		setFoldState();
	} catch (ex) {}
}

function setFoldState() {
	try {
		switch (readCookie('divImageActivityOverflow')) {
			case '': return;
			case 'hidden':
				xHeight('divImageActivity', 32);
				xGetElementById('divImageActivity').style.overflow = 'hidden';
				xGetElementById('tdImageActivity').setAttribute("class", "ImagePaneHeaderClosed");
				xGetElementById('tdImageActivity').setAttribute("className", "ImagePaneHeaderClosed");
				break;
			case 'visible':
				xGetElementById('divImageActivity').style.height = '';
				xGetElementById('divImageActivity').style.overflow = 'visible';
				xGetElementById('tdImageActivity').setAttribute("class", "ImagePaneHeader");
				xGetElementById('tdImageActivity').setAttribute("className", "ImagePaneHeader");
				break;
		}
		switch (readCookie('divInfoActivityOverflow')) {
			case '': return;
			case 'hidden':
				xHeight('divInfoActivity', 23);
				xGetElementById('divInfoActivity').style.overflow = 'hidden';
				xGetElementById('tdInfoActivity').setAttribute("class", "InfoPaneHeaderClosed");
				xGetElementById('tdInfoActivity').setAttribute("className", "InfoPaneHeaderClosed");
				break;
			case 'visible':
				xGetElementById('divInfoActivity').style.height = '';
				xGetElementById('divInfoActivity').style.overflow = 'visible';
				xGetElementById('tdInfoActivity').setAttribute("class", "InfoPaneHeader");
				xGetElementById('tdInfoActivity').setAttribute("className", "InfoPaneHeader");
				break;
		}
		
		pluginFoldState();
	} catch (ex) {}
}

function init() {
	saveCookie('slideShow', '', -1);
	setFoldState();
	resizeHandler();
<ja:if test="$useFolderView">	
	try {
		var sFolders = readCookie('Folders');
		if (sFolders.length > 0)
			sFolders = sFolders.substring(1,sFolders.length - 1);
		var arrFolders = sFolders.split('||');
		for (var i = 0; i < arrFolders.length; i++) {
			try {
				document.images['img' + arrFolders[i]].src = '$resPath/TreeMinus.gif';
				document.getElementById('folder' + arrFolders[i] + 'c').style.display = 'block';
			} catch (ex) {}
		}
		if (readCookie('ShowFolders') == 'true')
		    xLeft('divFolders', 0);
	} catch (e) {}
</ja:if>
<%
sOutput = "";
// If we are using plug-ins - include their onLoad js-files
if (Plugins != null && Plugins != void) {
	String[] arrPlugins = Plugins.split("#");
	for (int i = 0; i < arrPlugins.length; i++) {
		texts = getResources(arrPlugins[i]);
		sOutput += getOnLoadJavascript(arrPlugins[i], true);
	}
	if (sOutput != "") {
		sOutput = "try {\n" + sOutput + "} catch (ex) {}\n";
	}
}
%><%=sOutput%>
}
function resizeHandler() {
<ja:if test="$useFolderView">	
    try {
		xHeight('divTree', xClientHeight()-25);
	} catch (e) {}
</ja:if>
	xHeight('divActivity', parseInt(xClientHeight(),10) + parseInt(xScrollTop(),10));
}
window.onresize = resizeHandler
window.onscroll = resizeHandler
</script>
</head>
<body onload="init();" ID="index">
<script language="javascript">
if (navigator.userAgent.indexOf('Opera')!=-1)
	document.write('<style>\ndiv.Photo {\ndisplay: inline-block;\nfloat: none;\n}\n</style>');
</script>
<div id="divMainHeader"><%=title%> <% out.print(imageCount())%></div>
<div id="divMain">
<%
	String sFirstSlide = "";
%>
<ja:rowiterator><%
sOutput = "";
// If we are using plug-ins - parse any rowiterator templates found
if (Plugins != null && Plugins != void) {
	String[] arrPlugins = Plugins.split("#");
	for (int i = 0; i < arrPlugins.length; i++) {
		// Read localized strings for plug-in
		texts = getResources(arrPlugins[i]);
		
		File plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/rowiterator.htt");
		if (plg.exists())
			sOutput += engine.processTemplate(IO.readTextFile(plg));
	}
}
%><%=sOutput%><ja:coliterator><%
sOutput = "";
// If we are using plug-ins - parse any coliterator templates found
if (Plugins != null && Plugins != void) {
	String[] arrPlugins = Plugins.split("#");
	for (int i = 0; i < arrPlugins.length; i++) {
		// Read localized strings for plug-in
		texts = getResources(arrPlugins[i]);
		
		File plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/coliterator.htt");
		if (plg.exists())
			sOutput += engine.processTemplate(IO.readTextFile(plg));
	}
}
%><%=sOutput%><ja:if exists="iconPath">
</ja:if>
<ja:else>
<%
	if (sFirstSlide.equals("")) {
		sFirstSlide = closeupPath;
	}
%>
</ja:else>
<div class="Photo" align="center"><div class="imgBorder" align="center"><a href="$closeupPath"><%=spacerImage(thumbHeight)%><img src="$thumbPath" width="$thumbWidth" height="$thumbHeight" border="0"/><%=spacerImage(thumbHeight)%></a></div><a href="$closeupPath" class="Photo">$fileName</a></div>
	</ja:coliterator>
</ja:rowiterator>
</div>
<% sOutput = ""; %>
<ja:if exists="Plugins">
<%
String[] arrPlugins = Plugins.split("#");
for (int i = 0; i < arrPlugins.length; i++) {
	// Read localized strings for plug-in
	texts = getResources(arrPlugins[i]);

	// Panel common to index and slide pages
	File plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/panel.htt");
	if (plg.exists()) {
		sOutput += renderPanel("Panel" + i.toString(), getText("panelTitle"), engine.processTemplate(IO.readTextFile(plg))) + "<br/>";
		jsFoldState += renderFoldState("Panel" + i.toString());
	}
	// Panel exclusive to index page
	plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/panelIndex.htt");
	if (plg.exists()) {
		sOutput += renderPanel("PanelIndex" + i.toString(), getText("panelIndexTitle"), engine.processTemplate(IO.readTextFile(plg))) + "<br/>";
		jsFoldState += renderFoldState("PanelIndex" + i.toString());
	}
	// Common javascript file
	plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/javascript.js");
	if (plg.exists())
		jsPlugins += IO.readTextFile(plg);
	// Javascript file exclusive to index page
	plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/javascriptIndex.js");
	if (plg.exists())
		jsPlugins += IO.readTextFile(plg);
	
	// Get reference to plugin directory
	File pluginDir = new File(skinDirectory, "plugins/" + arrPlugins[i]);
	
	// Evaluate all templates starting with "index_"
	File[] templates = getIndexTemplates(pluginDir);
	for (int j = 0; j < templates.length; j++) {
		String sName = templates[j].getName();
		File newFile = new File(outputDirectory, sName.substring(6, sName.length() - 4) + engine.getPageExtension());
		engine.processTemplateFile(templates[j], newFile);
	}
	
	// If this is the first time the index template is used - check to see if there are any
	// templates that should be rendered only once.
	if (level == 0 && (indexNum == null || indexNum == void || indexNum == 0)) {
		templates = getOnceTemplates(pluginDir);
		for (int j = 0; j < templates.length; j++) {
			String sName = templates[j].getName();
			File newFile = new File(outputDirectory, sName.substring(5, sName.length() - 4) + engine.getPageExtension());
			engine.processTemplateFile(templates[j], newFile);
		}
	}
	
	// Adding to activities panel
	plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/panelActivities.htt");
	if (plg.exists())
		sActivitiesPanel += renderPanelRow(engine.processTemplate(IO.readTextFile(plg)), "Image");
	plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/panelActivitiesIndex.htt");
	if (plg.exists())
		sActivitiesPanel += renderPanelRow(engine.processTemplate(IO.readTextFile(plg)), "Image");

	// Adding to information panel
	plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/panelInformation.htt");
	if (plg.exists())
		sInformationPanel += renderPanelRow(engine.processTemplate(IO.readTextFile(plg)), "Info");
	plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/panelInformationIndex.htt");
	if (plg.exists())
		sInformationPanel += renderPanelRow(engine.processTemplate(IO.readTextFile(plg)), "Info");
}
%>
</ja:if>
<div id="divActivity">
<div id="divImageActivity">
<table border="0" cellspacing="0" cellpadding="0" width="185">
<tr>
	<td colspan="3" width="185" class="ImagePaneHeader" id="tdImageActivity" onclick="toggleVisibility('divImageActivity'); return false;">$text.imageActivities<img src="$resPath/1x1.gif" border="0" alt="" width="1" height="21" style="visibility: hidden;" /></td>
</tr>
<ja:if exists="parentIndexPage">
<tr>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
	<td width="183" class="ImagePaneRow"><a href="$parentIndexPage" class="ImagePaneRow"><img src="$resPath/FolderUp.gif" border="0" align="absmiddle" style="margin-right: 5px;"/>$text.upOneLevel</a></td>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
</tr>
</ja:if>
<%
if (!sFirstSlide.equals("")) {
out.print("<tr>" +
"	<td width=\"1\" class=\"ImagePaneFrame\"><img src=\"$resPath/1x1.gif\" width=\"1\" height=\"1\"/></td>" +
"	<td width=\"183\" class=\"ImagePaneRow\"><a onclick=\"setSlideShowCookie();\" href=\"" + sFirstSlide + "\" class=\"ImagePaneRow\"><img src=\"$resPath/Slideshow.gif\" border=\"0\" align=\"absmiddle\" style=\"margin-right: 5px;\"/>$text.showSlideshow</a></td>" +
"	<td width=\"1\" class=\"ImagePaneFrame\"><img src=\"$resPath/1x1.gif\" width=\"1\" height=\"1\"/></td>" +
"</tr>");
}
%>
<ja:if exists="totalIndexes">
<ja:if exists="nextIndexPage">
<tr>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
	<td width="183" class="ImagePaneRow"><a href="$nextIndexPage" class="ImagePaneRow"><img src="$resPath/Forward.gif" border="0" align="absmiddle" style="margin-right: 5px;"/>$text.nextPage</a></td>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
</tr>
</ja:if>
<ja:if exists="previousIndexPage">
<tr>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
	<td width="183" class="ImagePaneRow"><a href="$previousIndexPage" class="ImagePaneRow"><img src="$resPath/Back.gif" border="0" align="absmiddle" style="margin-right: 5px;"/>$text.previousPage</a></td>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
</tr>
</ja:if>
</ja:if>
<ja:if test="$useFolderView">
<tr>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
	<td width="183" class="ImagePaneRow"><a onclick="saveCookie('ShowFolders', 'true'); xLeft('divFolders',0); return false;" href="#" class="ImagePaneRow"><img src="$resPath/IconFolderOpen.gif" border="0" align="absmiddle" style="margin-right: 5px;"/>$text.folders</a></td>
	<td width="1" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
</tr>
</ja:if>
<%=sActivitiesPanel%>
<tr>
	<td width="185" colspan="3" class="ImagePaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
</tr>
</table>
</div>
<div id="divInfoActivity">
<table border="0" cellspacing="0" cellpadding="0" width="185">
<tr>
	<td colspan="3" width="185" class="InfoPaneHeader" id="tdInfoActivity" onclick="toggleVisibility('divInfoActivity'); return false;">$text.information</td>
</tr>
<%
if (sInformationPanel == "")
	sInformationPanel += renderPanelRow("", "Info");
%><%=sInformationPanel%>
<tr>
	<td width="185" colspan="3" class="InfoPaneFrame"><img src="$resPath/1x1.gif" width="1" height="1"/></td>
</tr>
</table>
</div>
<%=sOutput%>
<script language="javascript">
<%=jsPlugins%>
function pluginFoldState() {
<%=jsFoldState%>
}
</script>
<div id="divJAlbum">
Powered by <a href="$generatorUrl" target="_blank"><img src="$resPath/JAlbum.gif" border="0" alt="JAlbum" align="absmiddle"/></a>&nbsp;JAlbum
</div>
</div>
<ja:if test="$useFolderView"><ja:include page="Tree.htt"/></ja:if>
</body>
</html>