Index: other-projects/nz-flag-design/trunk/similarity-2d/flag-functions.jsp
===================================================================
--- other-projects/nz-flag-design/trunk/similarity-2d/flag-functions.jsp	(revision 29600)
+++ other-projects/nz-flag-design/trunk/similarity-2d/flag-functions.jsp	(revision 29600)
@@ -0,0 +1,64 @@
+
+  <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*" %>
+
+  <%!
+    public int GCD(int a, int b) {
+       if (b==0) return a;
+       return GCD(b,a%b);
+    }
+
+    ArrayList<File> listFilesForFolder(final File folder, String matchExt) {
+        ArrayList<File> fileList = new ArrayList<File>();
+
+        for (final File fileEntry : folder.listFiles()) {
+            if (fileEntry.isDirectory()) {
+                listFilesForFolder(fileEntry,matchExt);
+            } else {
+	         if (fileEntry.getName().toLowerCase().endsWith(matchExt)) {
+  	            fileList.add(fileEntry);
+		 }
+            }
+        }
+
+	return fileList;
+    }
+
+
+
+    public static Map<String, Integer> sortByComparator(Map<String, Integer> unsortMap) 
+    {
+ 
+	// Convert Map to List
+	List<Map.Entry<String, Integer>> list 
+	  = new LinkedList<Map.Entry<String, Integer>>(unsortMap.entrySet());
+ 
+	// Sort list with comparator, to compare the Map values
+	Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
+	      public int compare(Map.Entry<String, Integer> o1,
+                                 Map.Entry<String, Integer> o2) {
+	     	  return (o2.getValue()).compareTo(o1.getValue());
+	      }
+	});
+ 
+	// Convert sorted map back to a Map
+	Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
+	for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
+	    Map.Entry<String, Integer> entry = it.next();
+	    sortedMap.put(entry.getKey(), entry.getValue());
+	}
+												
+	return sortedMap;							
+    }
+/* 
+    public static void printMap(Map<String, Integer> map) 
+    {
+        for (Map.Entry<String, Integer> entry : map.entrySet()) {
+	    out.println("[Key] : " + entry.getKey() 
+                         + " [Value] : " + entry.getValue() + "br />");
+        }
+    }
+ */
+
+
+   %>
+
Index: other-projects/nz-flag-design/trunk/similarity-2d/list-flags.html
===================================================================
--- other-projects/nz-flag-design/trunk/similarity-2d/list-flags.html	(revision 29600)
+++ other-projects/nz-flag-design/trunk/similarity-2d/list-flags.html	(revision 29600)
@@ -0,0 +1,41 @@
+<!DOCTYPE html>  
+<html>
+  <head>
+    <meta charset="utf-8"/>
+  </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 = [ "Images/nz.gif" ];
+      </script>
+
+      <%@include file="flag-functions.jsp" %>
+
+      <!-- If JSP active, sets 'is_jsp_active' to true -->
+      <%@include file="list-flags.jsp" %>
+
+    </div>
+
+    <script>
+
+      if (!is_jsp_active) {
+        document.write("<div>Web server is no JSP active.  Unable to run flag comparison</div>");
+      }
+      var i;
+      for (i=0; i<img_list.length; i++) {
+        document.write("<img src=\"" + img_list[i] + "\" style=\"padding: 4px;\">\n");
+      }
+
+    </script>
+
+  </body>
+
+</html>
Index: other-projects/nz-flag-design/trunk/similarity-2d/list-flags.jsp
===================================================================
--- other-projects/nz-flag-design/trunk/similarity-2d/list-flags.jsp	(revision 29600)
+++ other-projects/nz-flag-design/trunk/similarity-2d/list-flags.jsp	(revision 29600)
@@ -0,0 +1,36 @@
+  <%
+      String docBase = getServletContext().getRealPath("/");
+      File similarityDir = new File(docBase,"similarity-2d");
+      File imagesDir = new File(similarityDir,"Images");
+
+      ArrayList<File> imageFileList = listFilesForFolder(imagesDir,".gif");
+
+      File imageUrlBase = new File("Images");
+
+      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();
+
+          //out.println("<img src=\"" + flagImageUrl + "\">");
+          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>");
+    }
+
+
+   %>
