Index: other-projects/nz-flag-design/trunk/main-form/kiwiana/display-svg.js
===================================================================
--- other-projects/nz-flag-design/trunk/main-form/kiwiana/display-svg.js	(revision 29964)
+++ other-projects/nz-flag-design/trunk/main-form/kiwiana/display-svg.js	(revision 29964)
@@ -0,0 +1,112 @@
+
+function displayFlags(img_list,$displayDiv)
+{
+    var img_list_len = img_list.length;
+
+    if (img_list_len==0) {
+	return;
+    }
+
+    img_list.sort();
+
+    var root_img_re = /^.*\/(.*?)\..*?$/;
+
+    var callback_count = 0;
+    
+    var i;
+    for (i=0; i<img_list.length; i++) {
+	var img_url     = img_list[i];
+	var img_matches = root_img_re.exec(img_url);
+	var title       = img_matches[1];
+	
+	var imageObj = new Image();
+
+	imageObj.onload = function() {
+	    callback_count++;
+	    
+	    if (callback_count == img_list_len) {
+
+		    // Done => wind things up
+	             doneDisplayKiwiana(img_list);
+            }
+	};
+
+
+	
+	imageObj.src     = img_url;
+        imageObj.height  = 150;
+	imageObj.title   = title.toUpperCase();
+	imageObj.country = imageObj.title;
+	imageObj.id      = "flag-img-" + i;
+
+
+	var $a = $('<a></a>');
+	$a.attr("href",img_url);
+	
+	$a.append(imageObj);
+
+	$displayDiv.append($a);
+    }
+}
+
+
+function doneDisplayKiwiana(img_list)
+{
+    console.log("doneDisplayKiwiana()");
+
+
+/*globals $*/
+/*jslint vars: true*/
+$('a').click(function() {'use strict';
+	var meta_str;
+	var href = this.href;
+	var target = window.parent;
+	// Convert Non-SVG images to data URL first 
+	// (this could also have been done server-side by the library)
+	if (this.href.indexOf('.svg') === -1) {
+
+		meta_str = JSON.stringify({
+			name: $(this).text(),
+			id: href
+		});
+		target.postMessage(meta_str, '*');
+
+		var img = new Image();
+		img.onload = function() {
+			var canvas = document.createElement('canvas');
+			canvas.width = this.width;
+			canvas.height = this.height;
+			// load the raster image into the canvas
+			canvas.getContext('2d').drawImage(this, 0, 0);
+			// retrieve the data: URL
+			var dataurl;
+			try {
+				dataurl = canvas.toDataURL();
+			} catch(err) {
+				// This fails in Firefox with file:// URLs :(
+				alert("Data URL conversion failed: " + err);
+				dataurl = "";
+			}
+			target.postMessage('|' + href + '|' + dataurl, '*');
+		};
+		img.src = href;
+	} else {
+		// Send metadata (also indicates file is about to be sent)
+		meta_str = JSON.stringify({
+			name: $(this).text(),
+			id: href
+		});
+		target.postMessage(meta_str, '*');
+		// Do ajax request for image's href value
+		$.get(href, function(data) {
+			data = '|' + href + '|' + data;
+			// This is where the magic happens!
+			target.postMessage(data, '*');
+			
+		}, 'html'); // 'html' is necessary to keep returned data as a string
+	}
+	return false;
+});
+
+}
+
Index: other-projects/nz-flag-design/trunk/main-form/kiwiana/index.jsp
===================================================================
--- other-projects/nz-flag-design/trunk/main-form/kiwiana/index.jsp	(revision 29964)
+++ other-projects/nz-flag-design/trunk/main-form/kiwiana/index.jsp	(revision 29964)
@@ -0,0 +1,100 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<!DOCTYPE html>  
+<html>
+  <head>
+    <meta charset="utf-8"/>
+
+    <link rel="stylesheet" href="../js/jquery-ui-1.11.2.smoothness/jquery-ui.min.css" />
+    <link rel="stylesheet" href="style.css" />
+
+    <script src="../../js/jquery-1.11.1.min.js"></script>
+    <script src="../../js/jquery-ui-1.11.2.smoothness/jquery-ui.js"></script>
+
+<!--
+    <script src="../../similarity-2d/js-lib/Colour.js"></script>
+-->
+
+    <script src="display-svg.js"></script>
+
+    <script>
+      $(function() {
+
+        if (!is_jsp_active) {
+          var mess = "<div>Web server is not JSP active.  Unable to display dynamic list of Kiwiana images</div>";
+          $('#kiwianaArea').append(mess);
+        }
+      
+        displayFlags(img_list,$('#kiwianaArea'));
+
+      });
+    </script>
+
+
+    <title>Kiwiana Shape Library</title>
+
+  </head>
+
+  <body>
+
+    <div style="display: none;">
+
+      <!-- 
+	 Set up a fallback position in case this page is accessed outside
+	 of a JSP context (i.e., the JSP blocks aren't executed) 
+	-->
+      <script>
+	var is_jsp_active = false;
+	var img_list = [ "import/nz.gif" ];
+      </script>
+
+      <%@include file="../../similarity-2d/flag-functions.jsp" %>
+
+      <!-- If JSP active, sets 'is_jsp_active' to true -->
+      <%@include file="list-kiwiana.jsp" %>
+
+    </div>
+
+   <div id="progressArea" style="display: none;">
+     <span id="loadingLabel">Loading: </span>
+     <div id="progressBar"></div>
+   </div>
+
+   <div id="kiwianaArea"></div>
+
+   <div id="go-to-dl" style="display: none;">
+     Visit the digital library collection of all the world's flags: <a href="/greenstone3/library/collection/world-flags/browse/CL1" target="dl">more ...</a>
+   </div>
+
+   <div id="go-to-nz-dl" style="display: none;">
+     Visit the digital library collection of alternative New Zealand flag deisgns: <a href="http://localhost:8383/greenstone3/library/collection/aotearoa/browse/CL1" target="dl">more ...</a>
+   </div>
+
+
+    <script>
+      function getParameterByName(name) {
+        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
+        results = regex.exec(location.search);
+        return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+      }
+
+      //var mode = $.urlParam('mode');
+      var mode = getParameterByName('mode');
+
+/*
+      console.log("*** mode = " + mode);
+      if (mode && mode == "nz") {
+        document.getElementById('go-to-nz-dl').style.display="block";
+        //$('#go-to-nz-dl').show();
+      }
+      else {
+        document.getElementById('go-to-dl').style.display="block";
+        //$('#go-to-dl').show();
+      }     
+*/
+
+    </script>
+
+  </body>
+
+</html>
Index: other-projects/nz-flag-design/trunk/main-form/kiwiana/list-kiwiana.jsp
===================================================================
--- other-projects/nz-flag-design/trunk/main-form/kiwiana/list-kiwiana.jsp	(revision 29964)
+++ other-projects/nz-flag-design/trunk/main-form/kiwiana/list-kiwiana.jsp	(revision 29964)
@@ -0,0 +1,36 @@
+  <%
+      String docBase = getServletContext().getRealPath("/");
+      File mainFormDir = new File(docBase,"main-form");
+
+      String imagesStr = "kiwiana";
+      File imagesDir = new File(mainFormDir,imagesStr);
+
+      ArrayList<File> imageFileList = listFilesForFolder(imagesDir,"svg");
+
+      //File imageUrlBase = new File(imagesStr);
+      File imageUrlBase = new File(".");
+
+      //String action = request.getParameter("action");
+
+      out.println("<script>");
+      out.println("var dynamic_img_list = [ ");
+      boolean first_entry = true;
+      for (final File fileEntry : imageFileList) {
+          String flagImageUrl = imageUrlBase + "/" + fileEntry.getName();
+
+          if (first_entry) {
+              out.println("\"" + flagImageUrl + "\"");
+              first_entry = false;
+          }
+          else {
+              out.println(",\"" + flagImageUrl + "\"");
+          }
+      }
+      out.println("];");
+
+      out.println("is_jsp_active = true;");
+      out.println("img_list = dynamic_img_list;");
+
+      out.println("</script>");
+
+   %>
